java.io.FileNotFoundException when writing uploaded file to disk via getRealPath()

♀尐吖头ヾ 提交于 2019-11-26 21:07:05
BalusC

Never use getRealPath()

You should not save uploaded files in the deploy folder. I have explained this so many times before. One of those explanations can be found in this answer: Uploaded image only available after refreshing the page.

Any JSP/Servlet code snippet found on some blog/article which ever uses the getRealPath() method should be taken with a huge bag of salt. Its quality and the knowledge of the author should strongly be questioned. There is namely no sensible real world use case for that method.

Save uploaded files in a fixed path outside the deploy folder. See also How do I set the folder for storing file uploads using Commons FileUpload.

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