2013-05-13 150 views
0

我想從HTML文件輸入中上傳文件。getServletContext()。getRealPath(「/」)省略正斜槓(/)

我正在使用Apache Commons FileUpload併成功上傳文件。然而,當我嘗試存儲我的MySQL的文件路徑,它收藏起來沒有文件路徑代碼:

String uploadFolder = getServletContext().getRealPath("/"); 
String fileName = new File(item.getName()).getName(); 
filePath = uploadFolder+"/"+fileName; 
File uploadedFile = new File(filePath); 

這是我正在試圖存儲文件。

樣本文件路徑存儲

C:UsersLashDesktopworkspace3.metadata.pluginsorg.eclipse.wst.server.core mp0wtpwebappsJavaECom/download doget.txt 
+2

嘗試讓你的問題和標題更清楚... – informatik01 2013-05-13 21:51:22

回答

0

我不知道這個問題是什麼,而是做你貼的代碼是做操作如下正確的方法:

File uploadFolder = new File(getServletContext().getRealPath("/")); 
String fileName = new File(item.getName()).getName(); // not sure what's going on here 
File uploadedFile = new File(uploadFolder, fileName); 
+0

即時通訊如果其誤導,但該文件被存儲在路徑中,對不起。當我提取該路徑並將其保存在mysql中時,它將忽略/字符 – Kriss 2013-05-15 13:21:29