下面是我用來上傳文件到服務器的代碼。但代碼拋出一個異常目錄或文件未找到..上傳文件到服務器拋出文件或目錄未找到異常
ResourceBundle rs_mail = ResourceBundle.getBundle("mail");
String upload_path = rs_mail.getString("upload_path");
File file = null;
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
// Parse the request to get file items.
List fileItems = upload.parseRequest(request);
// Process the uploaded file items
Iterator i = fileItems.iterator();
while (i.hasNext()) {
FileItem fi = (FileItem) i.next();
File uploadDir = new File(upload_path);
if (!uploadDir.exists()) {
uploadDir.mkdir();
}
file = new File(upload_path + file.separator + fi.getName());
fi.write(file);
}
任何一個可以指出該異常的原因..屬性文件
內容
upload_path = ../../../upload
異常很清楚:「找不到目錄或文件。」您是否嘗試過調試代碼以確定哪些文件或目錄不存在? – Vulcan
在此行中引起異常fi.write(file); –
'upload_path'是普通文件而不是目錄嗎? 'fi'有沒有斜槓? – chrylis