aspose file tools*
The moose likes Java in General and the fly likes File.createTempFile naming problem    Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "File.createTempFile naming problem    " Watch "File.createTempFile naming problem    " New topic
Author

File.createTempFile naming problem

Aniruddha Jadhao
Greenhorn

Joined: May 10, 2006
Posts: 24
Hello All,

I am using WIN XP .I am creating a temporary file with the following code

File temporaryDll = File.createTempFile("abcd", ".dll");



In the temp directory , though I marked in code

deleteOnExit

to temporaryDll , it creates files with abcd1234.dll , abcd1235.dll n so on .

The temp directory gets filled up with these number of dlls with diff suffix. Is there any mechanism or any code snippet will I get , to make sure that only one dll will get created n deleted after JVM termination.How can I check in the code , file already exists or not , because at every time it create new filename?

I have tried by deleting all abcdxxxx.dll from temp dir , I ran the code but wondered after watching in temp dir , abcd1234.dll file created instead abcd.dll .

Looking forward for help.
thanks
Ani
Usha Seetharaman
Greenhorn

Joined: Apr 08, 2008
Posts: 15
The culprit here is the bug 4171239 in
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4171239

WIN32 JVM does not delete a file that is in open state. To avoid this you might need to close the file before calling deleteOnExit().

However I am using 1.4.2_03 and when I use deleteOnExit(), it does not create the temp files once the process is completed. I guess the bug got fixed. Let me know which version you are using.
[ April 17, 2008: Message edited by: Usha Seetharaman ]
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

Usha:Sorry, the post got cut in between..


You can edit your post by clicking this image on top of your post.


apigee, a better way to API!
Aniruddha Jadhao
Greenhorn

Joined: May 10, 2006
Posts: 24
Hello,
Thanks for your reply.
I am using jdk 1.5 . I have already gone through the link sent by you though.
What currently I have done is renamed the file to the origional dll after creation i.e. abcd12345.dll to abcd.dll for the first time & reusing that after that.Here I cannt close the file till my application submodules dont need it.
By the way is there any workaround for deleting that file other that closing?
thanks
Ani
Usha Seetharaman
Greenhorn

Joined: Apr 08, 2008
Posts: 15
One option could be once your application starts, i.e. the JVM starts up, delete all temp files you created starting with abcd*.dll since at that moment there are no files open. That might reduce your temp directory getting flooded with these files.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: File.createTempFile naming problem
 
Similar Threads
How to get the File Property Informations?
getting a randomly generate directory onto the classpath
How to rename a file in JAVA ?
Creating Temp Files
Path for Temporary Directory