本文主要是介绍解决java.io.FileNotFoundException: D:\tempfile (拒绝访问。),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
问题:java.io.FileNotFoundException: D:\tempfile (拒绝访问。)at java.io.FileOutputStream.open(Native Method)at java.io.FileOutputStream.(FileOutputStream.java:221)at java.io.FileOutputStream.(FileOutputStream.java:171)at com.sh.xy.servlet.UploadServlet.doPost(UploadServlet.java:55)at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)...
解决办法:在填写文件的路径时一定要具体到文件
源码:
public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {System.out.println("已经接收到请求");//从request当中获取流信息InputStream fileSource = request.getInputStream();String tempFileName = "D:/tempfile.png";//tempFile指向临时文件File tempFile = new File(tempFileName);//outputStream文件输出流指向这个临时文件FileOutputStream outputStream = new FileOutputStream(tempFile);byte b[] = new byte[1024];int n;while((n=fileSource.read(b)) != -1){outputStream.write(b, 0, n);}//关闭输入输出流outputStream.close();fileSource.close();}}
这篇关于解决java.io.FileNotFoundException: D:\tempfile (拒绝访问。)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!