aspose file tools
The moose likes Java in General and the fly likes On Deleting External Files Using Java Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "On Deleting External Files Using Java" Watch "On Deleting External Files Using Java" New topic
Author

On Deleting External Files Using Java

michael echavez
Greenhorn

Joined: Feb 07, 2005
Posts: 18
Hi! My program, unfortunately, produces a lot of temporary text (.txt) files when executed. I need help deleting them after being used. These temporary files are used by different classes at different points in time while the main program runs. Is there a method or a function in java that could call on system commands from the Operating System (Windows xp sp2 in particular)?
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2341
There is a method in java.io.File that will delete files
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24061
    
  13

You can just say

new File(theFileName).delete()

to delete a file right away, or (and this is perhaps closer to what you want) you can tell Java to clean up a file with the program quits by saying

new File(theFileName).deleteOnExit()


[Jess in Action][AskingGoodQuestions]
michael echavez
Greenhorn

Joined: Feb 07, 2005
Posts: 18
Thanks Ernest Friedman-Hill!!!
That was exactly what i needed, thank you so much!
Also, thank you for the hint Keith Lynn!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: On Deleting External Files Using Java
 
Similar Threads
Cannot execute binary file on linux
Memory contents as file
Picked up _JAVA_OPTIONS
Error compiling my first servlet
diff between path & classpath