There is a program that sometimes needs to read data from files. In the program I specify the path:

File fileRoot = new File(".\\src\\Resources"); 

However, if you create a jar, the program does not find these folders. What path should be indicated for the program to read these files when transferring the jar file to another computer (of course, the Resources folder is transferred along with the jar)?

It is not necessary to include a folder in the project itself, there may be different files.

1 answer 1

This is how you can do this universally, for the file that lies next to the jar:

 InputStream is = getClass().getClassLoader().getResouceAsStram("./file.txt"); 

here with this file allocation

 ./ |__ *.jar |__ file.txt 
  • This one helped: File fileRoot = new File (System.getProperty ("user.dir") + "\\ Resources"); - Alexander Dorofeev