File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

File.createTempFile naming problem

 
Aniruddha Jadhao
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1638
IntelliJ IDE Java MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Usha:Sorry, the post got cut in between..


You can edit your post by clicking this image on top of your post.
 
Aniruddha Jadhao
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic