java.io.FileNotFoundException: D:/TradeOrder.xls (No such file or directory)
代碼中使用 Windows 絕對路徑 D:/backTradeOrder.xls,Linux 檔案系統無 D:/ 掛載點,導致 FileOutputStream 找不到路徑。
// application.properties
file.upload.dir=/data/upload/
@Value("${file.upload.dir}") String uploadDir;Path path = Paths.get(uploadDir, "backTradeOrder.xls");
Files.createDirectories(path.getParent());
try (OutputStream out = Files.newOutputStream(path)) {
workbook.write(out);
}Paths.get() 或 File(String parent, String child) 建構子處理。將 D:/ 改為 Linux 實際掛載路徑(如 /home/app/upload/),並確保目錄存在且應用進程有寫入權限。