There is a program that needs to be read from a .txt file that is edited by a person or other programs. And at the design stage, that is, in the idea itself, these files were thrown into the project folder and there were no problems.

But the project still needs to be collected, and the assembled project does not see the relative path from the jar. How can I point the way relative to jar's?

  • And where is the txt inside the jar or near or where? - And
  • The function of reading a file as a JAR resource and as an external file will be different. Accordingly, the paths to the files will be radically different in the form of entries. Specify what option you need. Should the file be located in a JAR or outside a JAR package? In your question it is clear only what was one thing, but it became another. - Rootware

1 answer 1

Try to specify file paths relative to the project root. For example:

 File file = new File("src/test/text.txt");