我想將上傳的圖像寫入某個文件夾,但聽到第一次嘗試我認爲將它寫入到通過使用「request.getRealPath(」「)獲得的相同路徑「,在執行程序流程後順利完成了任何錯誤,但我無法找到它寫入的圖像......!當我通過調試程序檢查我來了解一些奇怪的路徑,我不能找到,即在java中使用OutputStream將圖像寫入特定文件夾
「/home/Software/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0 /wtpwebapps/elibrary/roronoa-zoro-wallpapers.jpg「
我能找到」/ home/Software/workspace /「和」last =>/elibrary /「是我的項目名稱。
目前我使用Spring MVC的3.2
這是我的控制器代碼
@RequestMapping(value = "/catalogue/catalogueImageUpload.action",method=RequestMethod.POST)
public void getimportedImage(USerDetails uploadItem,HttpServletRequest request) {
try {
MultipartFile file = uploadItem.getFileData();
String fileName = null;
InputStream inputStream = null;
OutputStream outputStream = null;
inputStream = file.getInputStream();
fileName = request.getRealPath("") + file.getOriginalFilename();
System.out.println(request.getRealPath("") + file.getOriginalFilename());
outputStream = new FileOutputStream(file.getOriginalFilename());
int readBytes = 0;
byte[] buffer = new byte[40000];
while ((readBytes = inputStream.read(buffer, 0, 10000)) != -1) {
outputStream.write(buffer, 0, readBytes);
}
outputStream.close();
inputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
我想要的......?
=>我想寫在特定的文件夾圖片我能找到它,它可能是在項目工作空間,或任何驅動器,或在某些文件夾中的項目表示圖像文件夾
已經設置您的操作系統,以顯示隱藏文件夾? –
雅我現在我刪除了request.getRealPath(「」),現在我能夠在eclipse文件夾中找到圖像我如何才能在項目內寫入圖像 – user2086370