閱讀我讀從PDF文件從Java
try {
File pdfFile = new File("ffile.pdf");
PDFParser parser = new PDFParser(new FileInputStream(pdfFile));
parser.parse();
COSDocument cosDoc = parser.getDocument();
PDFTextStripper pdfStripper = new PDFTextStripper();
PDDocument pdDoc = new PDDocument(cosDoc);
//do sth
} catch (Exception e) {
System.err.println("An exception occured in parsing the PDF Document."
+ e.getMessage());
}
有的時候一些文本關閉一個PDF文件,我得到這個錯誤:
WARNING [Finalizer] org.apache.pdfbox.cos.COSDocument.finalize Warning: You did not close a PDF Document
我在這兒,看一個類似的qustion它說我必須關閉打開的文件。所以,我加
finally{
pdfFile.close(); //<-
}
但Netbeans標記錯誤close()
說無法找到符號。 那我要結束什麼?我也試過parser.close()
,但這行也是從Netbeans標記爲錯誤的。
你試圖關閉什麼,你在你的代碼中給了它什麼名字? – Stultuske
我想關閉我加載的文件,這是'pdfFile' – yaylitzis
您需要關閉COSDocument,而不是解析器。 – bmargulies