Delete Temporary Files on Exit

Sometimes your application requires holding data in a temporary file. I’ve had to do this when printing a PDF file. The following bit of code demonstrates how to create a temporary file and delete said file when the program terminates.

File temp = File.createTempFile("SomePrefix", ".pdf");

The file is created in the system’s temp directory, see the Java property.

Related posts:

  1. Make and Delete Directories
  2. Reading Client-side Files with XPCOM
  3. Class HighLite File
  4. Accessing Local Files With Mozilla XPCOM
  5. Java Web Service with HTTPS
  6. Print a PDF Document in Java

Leave a Reply