2013-04-20 67 views
0

我想上传一个文件到我的项目相对路径。如果我想将文件保存在项目路径中,CommonsMultipartFile的文件上传路径应该是什么?

webapp/fileUpload /是我希望文件上传的路径。

所以当我把它给了我

java.io.FileNotFoundException: http:\localhost:8080\SpringDemo\fileUpload\design.txt(The filename, directory name, or volume label syntax is incorrect) 

我不理解什么应该是正确的道路的路径

CommonsMultipartFile commonsFile = user.getImage(); 
String fileName = commonsFile.getOriginalFilename(); 

File destFile = new File("http://localhost:8080/SpringDemo/fileUpload/",fileName); 

I want to save it under my project folder and not on any other path so I am using http:\localhost:8080\SpringDemo\fileUpload\as the path. 

When i paste http://localhost:8080/SpringDemo/fileUpload/abc.txt into my browser it shows me the file.(abc.txt) 

我不理解什么应该是正确的道路。

请告诉我正确的做法。

在此先感谢。

惊鼓

回答

0

首先,你保存范围内的任何文件都将丢失,如果你取消部署应用程序,所以一定要确保这就是你想要的。

至于你的问题,http://localhost/etc/and/so/on是你的应用程序的URL,而不是文件路径。

文件路径是底层文件系统的真实路径。

比方说,你正在使用Tomcat,它安装在/ usr /股,你的应用程序中的文件路径可能是这样的:/usr/share/tomcat/webapps/yourapp/somewhere/you/want/files/stored/some-file.txt

0

您指定的位置是一个目录,而不是文件。另外,我建议将文件部分发送到一个php/jsp,它将完成额外的检查并最终存储它。

相关问题