【发布时间】:2016-01-07 11:25:13
【问题描述】:
请,当我在 tomcat7/webapp/myapp.war 中部署应用程序并通过 Web 浏览器运行此应用程序时,我找不到输出文件。
我的应用程序存储一些结果文件如下:
try {
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("/home/user/Desktop/myfile.txt", true)));
out.println("some text");
out.close();
} catch (IOException e) {
//exception handling left as an exercise for the reader
}
输出文件在哪里?
【问题讨论】:
-
至少在上面的代码中,我看到您正在捕获 IOException 并默默地忽略它。如果在打开或写入文件时出现任何异常(权限、不存在等),您将不会了解它。您能否在 catch 块中添加 e.printStackTrace() 并检查 tomcat 日志以查看它是否抛出任何与文件相关的异常。
标签: java file tomcat7 printwriter