2013-04-20 64 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,它將完成額外的檢查並最終存儲它。

相關問題