Reputation: 43
I am opening a PDF File that I have created with iText. Without opening it in PDF Renderer and just opening it normally and closing it I can delete and overwrite to the file. However once I use PDF Renderer to open it then I close it. I am unable to delete the PDF or replacing it.
ByteBuffer buf;
...
randomAccessFile = new RandomAccessFile(new File(file), "r");
fileChannel = randomAccessFile.getChannel();
buf = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, fileChannel.size());
pdfFile = new PDFFile(buf);
Code here then gets the image and puts it into a panel.
Then I close the above items.
It is still opened somewhere but I can not figure out where, any help is appreciated.
Upvotes: 0
Views: 1467
Reputation: 109547
The error seems to be in the unshown rest (or closing the fileChannel).
PDFFile pdfFile = new PDFFile(new File(file));
PdfReader pdfReader = pdfFile.getPdfReader();
try {
...
} finally {
pdfReader.close();
}
Upvotes: 1
Reputation: 3184
Do you close the file? If you still have an Open file, Java cannot delete it.
Upvotes: 0