Java version 1.2 or later has File.createTempFile( String prefix, String suffix, File directory) for creating uniquely named temporary files. Unfortunately you still have to manually delete these files when you are finished with them. By default, Java puts temporary files in C:\Users\user\AppData\Local\Temp\
Unlike C,Java version 1.1 does not have methods for generating unique temporary filenames. I have written a getTempFile method.
Here is a slightly smarter version of Java version 1.2 or later ’s File.createTempFile() that will let you specify either a directory to create the temp file in, or a file in whose directory to create the file in. You need the logic of this smarter version if you want to write a utility that replaces the input file with the processed output from a renamed temp file.
This method is available as part of the com.mindprod.hunkio.
I am horrified to discover than even after 36 years years Microsoft still does not understand the temporary files problem.
When a program crashes, it does not delete its temporary files. Over the years your disk fills with junk.
Windows does not:
Here are three ways we could handle the probem of orphaned temporary files:
To use tmpfs, make sure your kernel can handle 'tmpfs', then add the following line into /etc/fstab:
tmpfs /tmp tmpfs noatime,mode=1777 0 0 then either reboot or 'init s’ then 'init {runlevel}', depending on preferences and OS configuration. (Don’t just mount /tmp unless you’re sure nothing is using it. X in particular sticks files in there — /tmp/.X11-unix/Xn, presumably for its Unix sockets.)
We need more than just a convention. If the OS knew a file were a temp it would know to place it in prime real estate, perhaps even on an SSD or virtual RAM (Random Access Memory). It could automatically clean it up. Backup software would automatically avoid backing up such files.
This page is posted |
http://mindprod.com/jgloss/temporaryfiles.html | |
Optional Replicator mirror
|
J:\mindprod\jgloss\temporaryfiles.html | |
Please read the feedback from other visitors,
or send your own feedback about the site. Contact Roedy. Please feel free to link to this page without explicit permission. | ||
Canadian
Mind
Products
IP:[65.110.21.43] Your face IP:[3.135.241.191] |
| |
Feedback |
You are visitor number | |