Hey guys.
With the experience in programming desktop application,it is straightforward to create a file and read that file,etc.The path problem is trivial.
However,in web application,the path may cause problems.I know if I want to read a file I can use
InputStream is = config.getServletContext().getResourceAsStream("/rates.txt");
is this the only way to solve the path problem when reading a file in web application?
what can I do if I want to write file?How can I define the path for the file?
I have tested to pass a servlet-context-relative path like "/rates.txt" to FileWriter directly,it works fine.It writes something in the file in the web directory.But I donot understand how can the FileWriter find the right path to write file?Does the Tomcat server solve these problems automatically?
If I move the FileWriter out of web application.It just write the file in driver C,liek C:\rates.txt.
Thanks very much.
With the experience in programming desktop application,it is straightforward to create a file and read that file,etc.The path problem is trivial.
However,in web application,the path may cause problems.I know if I want to read a file I can use
InputStream is = config.getServletContext().getResourceAsStream("/rates.txt");
is this the only way to solve the path problem when reading a file in web application?
what can I do if I want to write file?How can I define the path for the file?
I have tested to pass a servlet-context-relative path like "/rates.txt" to FileWriter directly,it works fine.It writes something in the file in the web directory.But I donot understand how can the FileWriter find the right path to write file?Does the Tomcat server solve these problems automatically?
If I move the FileWriter out of web application.It just write the file in driver C,liek C:\rates.txt.
Thanks very much.