title: Java read file from resources from jar
body: <pre><code>public class Main {
    public static void main(String[] args) throws IOException {
      System.out.println("----------Start------------------");
      URL resource = Main.class.getClassLoader().getResource("test.txt");
      System.out.println("resource: "+ resource.getPath());
  
      File file = new File(resource.getPath());
      BufferedReader reader = new BufferedReader(new FileReader(file));
      String line;
      while ((line = reader.readLine()) != null) {
        System.out.println(line);
      }
      reader.close();
      System.out.println("----------End------------------");
    }
  }
  </code></pre>
  
  <p>If I run this code from IDEA - all work</p>
  
  <pre><code>----------Start------------------
  resource: /D:/javaHz/target/classes/test.txt
  1
  2
  3
  4
  5
  ----------End------------------
  </code></pre>
  
  <p>Process finished with exit code 0</p>
  
  <p>if I reun from java -jar - I get error</p>
  
  <pre><code>D:\hz&gt;java -jar hzTest-jar-with-dependencies.jar
  ----------Start------------------
  resource: file:/D:/hz/hzTest-jar-with-dependencies.jar!/test.txt
  Exception in thread "main" java.io.FileNotFoundException: D:\hz\file:\D:\hz\hzTe st-jar-with-dependencies.jar!\test.txt (Syntax error in file name, folder name, or volume label)
          at java.io.FileInputStream.open0(Native Method)
          at java.io.FileInputStream.open(FileInputStream.java:195)
          at java.io.FileInputStream.&lt;init&gt;(FileInputStream.java:138)
          at java.io.FileInputStream.&lt;init&gt;(FileInputStream.java:93)
          at java.io.FileReader.&lt;init&gt;(FileReader.java:58)
          at test.Main.main(Main.java:15)
  </code></pre>
  
  <p>I do not want use <code>getResourceAsStream</code></p>