Good afternoon, I can not understand why I stopped loading the resource I work in eclipse, the composition of the project and the location of the file did not change it in the resources package

enter image description here ,

but suddenly it became an error.

Java.lang.NullPointerException in thread "java.io.DataInputStream.read (DataInputStream.java:100) at com4j_example.Main.main (Main.java:68)

I use this design for download.

InputStream in = Main.class.getResourceAsStream("date.txt"); System.out.println(in); DataInputStream din = new DataInputStream(in); FileOutputStream outF = new FileOutputStream("C://Users/Desktop/resources/date.txt//"); byte[] buffer = new byte[1024]; int count = 0; while ((count=din.read(buffer)) != -1){ outF.write(buffer,0,count); } outF.flush(); outF.close(); 
  • What ide? What jar will she build? Open it in the archiver (jar is actually a normal zip) and see which folder the resource got into. May need to do so Main.class.getResourceAsStream ("resources / com4j_example / date / date.txt"); - Sergey

1 answer 1

Everything was decided by adding the resources folder in the bin package in the project, and then in the package to the project classes. The path turned out such

bin / "package name" /resources/date.txt