I was using the following c’tor in my java web application
public File(String pathname)
For example:
File =new File(“1.txt”);
Then I get the following file in the path:
C:\Program Files\Apache Software Foundation\Apache Tomcat 7.0.22\bin\1.txt
My question: why is this the default folder when using the above c’tor and also if there is any option to change it by default for the project folder for example.
Thanks
File for a relative path uses
System.getProperty("user.dir"), the application startup directory (which almost always is a bad idea). In a web application you want to use the Servlet’sgetRealPath("/1.txt")which goes relative from the web app directory. Note not\\but/.