FileNotFoundException (Permission Denied)

别等时光非礼了梦想. 提交于 2019-12-11 03:05:01

问题


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).

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?


回答1:


The answer was to chmod 777 instead of 666.



来源:https://stackoverflow.com/questions/18949922/filenotfoundexception-permission-denied

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!