I am trying to read a .txt file in a line in my code, which I placed directly in the /src/ directory, when I run it in a test case or with a static void main, the path output is correct. However, when I launch the application with the Tomcat server, the root path of the application indicates where I load Eclipse - D:\eclipse\... , while the correct path should be D:\workspace\myproject\src\ . Then, of course, he will never be able to find the file.
Below is my code:
String workDir = System.getProperty("user.dir"); String file = "numFile.txt"; File myFile = new File(workDir + file); String userPath = myFile.getPath();
So my questions are:
- (it can be dumb) Where do we usually place a text file?
- How can I change [
System.getProperty("user.dir"); ], so it will point to my project workspace?
Thanks!
Sharon
regarding your answer:
add the following arguments -Duser.home = 'Your Path', make sure you add -D at the beginning of your system variable. And you can put this variable in the “VM Arguments” field, presented on the “Parameters” tab, when you open the launch configuration when using the tomcat server.
I cannot find the place you are talking about. Is it in the Eclipse or Tomcat directory?
thanks
source share