how do i create http visible files from java web application?
How can I create files visible by http protocol from java web application in web/myFiles folder ?
Is this even possible ?
for the following code :
String realPath = getServletContext().getRealPath("/");
System.out.printl开发者_开发知识库n(realPath);
try {
BufferedWriter out = new BufferedWriter(new FileWriter( realPath + "\\myFiles\\test.txt"));
out.write("aString\nthis is a\nttest");
out.close();
} catch (IOException e) {
System.out.println("Exception " + e);
}
i keep getting the error :
Exception java.io.FileNotFoundException: C:\Documents and Settings\Andrei\My Documents\NetBeansProjects\SemanticCashUpV1.0\build\web\myFiles\test.txt (The system cannot find the path specified)
Yes possible,
You need to create file in public web area.
near to WEB-INF
Dir.
you can get path to public web space by
request.getServletContext().getRealPath("/");
精彩评论