LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   erasing a file with java (https://www.linuxquestions.org/questions/programming-9/erasing-a-file-with-java-320937/)

poeta_boy 05-07-2005 01:18 AM

erasing a file with java
 
Hello everyone:

I know I can create a file with java, and write there, but is there a way for me to erase a file too?

My question is because I need to create a temp file, where to store some info, and then (when the program ends) erase it, so I don't create a mess in the directory

is that possible?

thanks a lot

Poeta

kencaz 05-07-2005 01:34 AM

I'm not a Java programmer, however, I would not want Java having the capability of erasing files on my system... I have it turned of anyway. I am sure there is probably a way though...

KC

vladmihaisima 05-07-2005 01:53 AM

You can use:

File f=new File("temp");
f.delete(); // returns boolean if it succeded

Of course there could be a security exception depending of the security manager and the rights the program has (for a standalone application there is none - so no exception, but for applets threre are securitymanagers by default).

poeta_boy 05-07-2005 10:09 AM

thanks a lot.... It's an standalone, so there should be no problem...

thanks =)


All times are GMT -5. The time now is 04:10 PM.