java.io.FileNotFoundException: C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\jwgl003\upload\temp (拒绝访问。)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:179)
at java.io.FileOutputStream.<init>(FileOutputStream.java:131)
at org.apache.commons.fileupload.disk.DiskFileItem.write(DiskFileItem.java:416)
at com.jwgl.servlet.TongGaoServlet.updateTongGao(TongGaoServlet.java:346)
at com.jwgl.servlet.TongGaoServlet.doGet(TongGaoServlet.java:73)
at com.jwgl.servlet.TongGaoServlet.doPost(TongGaoServlet.java:529)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.jwgl.filter.EncodingFilter.doFilter(EncodingFilter.java:19)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)
问题出现的原因:
File f = new File(filePath);
item.write(f);
如果filePath是路径,不包含文件名称(a.txt)的话,在写进 f 时则会出现这个错误
解决办法:
保证filePath 还有文件名如 D:\upload\a.txt