He worked in Eclipse for Standart Edition, indicated a relative path and everything was fine, switched to Eclipse for Enterprise Edition, I am writing the same thing, it does not work. I decided to display the current path of the project, but it was not the path to my project that gave me, but the path where Eclipse lies, on a completely different disk of my computer.

  • As far as I understand, when I start the Tomcat server, I have the current directory to become this server, how can I make it so that the classes from the project see other files in this project in a relative path, because I specify the relative path to the file, they think that are near the server. - Yevgeny Efimenko

2 answers 2

To get the current (for the calling class) URL ->

String resours = TestClass.class.getResource("").toString(); 

the path to root or any other directory will either be cut off by substring or by calling the upper directory of the hierarchy ../../

    Try this:

     InputStream stream = getClass().getClassloader().getResourceAsStream("./test.txt"); 

    for the file named test.txt in the root of the web application