排查了代碼理論上不會出現FileNotFoundException問題
String staffCode) throws Exception { String path = "D:\\sss\\"+staffCode+"_"+(new SimpleDateFormat("yyMMddHHmmss").format(new Date()))+"\\"; // String path = "/data/file/" + staffCode + "_" + (new SimpleDateFormat("yyMMddHHmmss").format(new Date())) + "/"; log.error("獲取的路徑:" + path); String fileName = "上傳" + System.currentTimeMillis(); String filePath = path + fileName; fileNewPath.append(path); File file = new File(filePath); if (!file.exists()) { file.mkdirs(); } FileOutputStream fileOutputStream = new FileOutputStream(filePath + "/上傳" + System.currentTimeMillis() + ExcelTypeEnum.XLSX.getValue()); fileOutputStream.write(baos.toByteArray()); fileOutputStream.close(); genImages(list3, filePath); log.error("filePath" + filePath); return setZip(filePath, path, fileName);
后來發現三台服務器中只有一台在報錯,檢查服務器找到原因是/data/file文件夾的權限不夠的原因導致的