Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't my program delete the files it creates under Win7?

I've made a Java program in Eclipse. I started on Windows XP, but have recently upgraded.

As part of it's saving mechanism, the program writes the settings to a file settings_new.sav. If that goes ok, it deletes the settings.sav, and renames the new one to match the old name. While it worked under winXP (at least I thought it did, but I can't check now), under win7, it fails to delete the file, even though it was the program that created it (although, a different instance of the program).

The file is picked up by Eclipse and can be deleted from there quite happily. I can delete it manually. I am the admin on my own computer. The folder is just inside the workspace folder, and is not in Program Files (though, I have no idea if eventual users will install it there). The program can create and modify files just fine. It's not throwing any Exception, which I thought it would if it was win7 blocking it.

Any ideas?

like image 640
AlbeyAmakiir Avatar asked Sep 25 '11 04:09

AlbeyAmakiir


1 Answers

It is due to file-locking mechanism in java.Make sure you close the buffering streams such as BufferedReader, BufferedInputStream on that file when done.

like image 122
PraveenMax Avatar answered Sep 21 '22 14:09

PraveenMax