java.io.FileNotFoundException:
C:\mysoftware\apache-tomcat-7.0.37\webapps\friend2\upload\pic_3\E:\David_Liu\picture\Peter_Jackson.jpg
(文件名、目錄名或卷標語法不正確。)
代碼將**客戶端完整本地路徑**(E:\David_Liu\picture\Peter_Jackson.jpg)直接拼接到服務端儲存目錄後,導致路徑包含兩個盤符(C:\...pic_3\E:\...),Windows 無法識別。
String savePath = baseDir + File.separator + clientFileName; // clientFileName 含 E:\...
String fileName = new File(clientFileName).getName();String ext = fileName.substring(fileName.lastIndexOf('.'));
String uniqueName = UUID.randomUUID().toString() + ext;
File dest = new File(uploadDir, uniqueName);
切記:**永遠不要信任客戶端傳來的原始路徑**。取名、重命名、落庫三步走,文件上傳零事故!