3

I'm creating a pdf file in my java program.

After having it created to a specified Path, I'm opening it with the user's standard application.

File myFile = new File("F:/test.pdf");
Desktop.getDesktop().open(myFile);

My standard application for pdf files is for example Adobe Reader - so Adobe Reader opens up and displays the file. - So far so good.

Is there any way to delete this "test.pdf" after I close the file/my Adobe Reader?

itaton
  • 287
  • 2
  • 13
  • does Desktop.getDesktop().open(myFile) work in a blocking way? Which means, it stops execution of your application until you close your default pdf reader? – Miron Balcerzak Jun 25 '14 at 08:29

2 Answers2

1

You can create the file in the temp directory, so you will not have to worry about removing it.

To create a file in the temp directory you should use the File.createTempFile method.

Bartosz Mikulski
  • 525
  • 3
  • 17
1

Check the following link: Java: Check if file is already open

Run an infinite loop after you open the loop, as mentioned in the above thread, verify and close the file accordingly.

Thanks, JK

Community
  • 1
  • 1
HJK
  • 1,382
  • 2
  • 9
  • 19