| 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
|
|
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!
|
 |
 |
|
|
subject: On Deleting External Files Using Java
|
|
|