Java close PDF error
•
Java
I have this java code:
try {
PDFTextStripper pdfs = new PDFTextStripper();
String textOfPDF = pdfs.getText(PDDocument.load("doc"));
doc.add(new Field(campo.getDestino(),textOfPDF,Field.Store.NO,Field.Index.ANALYZED));
} catch (Exception exep) {
System.out.println(exep);
System.out.println("PDF fail");
}
Throw this:
11:45:07,017 WARN [COSDocument] Warning: You did not close a PDF Document
And I don't know why I should throw away this 1,2,3 or more
I found that cosdocument is a class and has a close () method, but I didn't use this class
I have this import:
import org.apache.pdf@R_328_2419@.pdmodel.PDDocument; import org.apache.pdf@R_328_2419@.util.PDFTextStripper;
Thank you:)
Solution
You are loading the pddocument but did not close it I suspect you need to do this:
String textOfPdf;
PDDocument doc = PDDocument.load("doc");
try {
textOfPdf = pdfs.getText(doc);
} finally {
doc.close();
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
