如何从web / myFiles文件夹中的java web应用程序创建http协议可见的文件?
这甚至可能吗?
代码如下:
String realPath = getServletContext().getRealPath("/");
System.out.println(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);
}
我一直收到错误:
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)
答案 0 :(得分:0)
是的,
您需要在公共网站区域创建文件。
靠近WEB-INF
Dir。
您可以通过
获取公共网络空间的路径 request.getServletContext().getRealPath("/");