Java FileNotFoundException(权限被拒绝)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18949922/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
FileNotFoundException (Permission Denied)
提问by Mike Nitchie
All, I'm using commons-FileUpload to allow my students to upload their assignments to my server through the class website. It works just fine running tomcat/eclipse on my local machine. However, when testing it on my server I have through digitalocean.com I am getting a FileNotFoundException (PermissionDenied).
所有,我正在使用 commons-FileUpload 允许我的学生通过课堂网站将他们的作业上传到我的服务器。在我的本地机器上运行 tomcat/eclipse 运行良好。但是,当我通过 digitalocean.com 在我的服务器上测试它时,我收到了 FileNotFoundException (PermissionDenied)。
Stack trace:
堆栈跟踪:
java.io.FileNotFoundException:
/uploads/cosc111fall2013/Assignment1/Program1.java (Permission denied)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:209)
at java.io.FileOutputStream.<init>(FileOutputStream.java:160)
at org.apache.commons.fileupload.disk.DiskFileItem.write(DiskFileItem.java:394)
at uploadServlet.Uploader.doPost(Uploader.java:127)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
The offending code:
违规代码:
try {
for (FileItem fi : uploaded) {
fi.write(new File(saveDirectory + fileName + "_"
+ FilenameUtils.getName(fi.getName())));
}
} catch (Exception e) {
e.printStackTrace();
response.sendRedirect("/uploadFailed.jsp");
return;
}
I just chmodded the directories that the program writes to so they are all drw-rw-rw-
. Any tips?
我只是修改了程序写入的目录,所以它们都是drw-rw-rw-
. 有小费吗?
采纳答案by Mike Nitchie
The answer was to chmod 777 instead of 666.
答案是 chmod 777 而不是 666。