記一次錯誤
背景:項目中有word轉pdf再轉圖片插入到pdf中防止修改pdf的方法,在word轉PDF時,在Windows上無問題,但是在linux上PDF文件沒有創建出來,下面是當時的代碼
try { long old = System.currentTimeMillis(); Document doc = new Document(inPath);// 原始word路徑 String pdfFile = outPath; FileOutputStream fileOS = new FileOutputStream(outPath); doc.save(fileOS, SaveFormat.PDF); long now = System.currentTimeMillis(); System.out.println("共耗時:" + ((now - old) / 1000.0) + "秒"); } catch (Exception e) { e.printStackTrace(); }
這是用outputStream傳入一個路徑,直接創建文件,但是Linux不能直接這么創建,需要先new一個file,然后再用outputStream往文件中插入數據