Why can't my program delete files created in Win7?

I created a Java program in Eclipse. I started working on Windows XP, but recently updated.

As part of the save mechanism, the program writes the settings to a file settings_new.sav. If all goes well, it will delete settings.savand rename the new one so that it matches the old name. Although it worked under winXP (at least I thought it was, but I can’t check now), under win7, it cannot delete the file, although it was the program that created it (although another instance of the program).

The file is selected by Eclipse and can be deleted quite happily from there. I can delete it manually. I am an administrator on my computer. The folder is located only inside the workspace folder and is not in the program files (although I have no idea if their end users can install it there). The program can create and modify files just fine. This throws no Exception, which I thought that if it were win7, it blocked it.

Any ideas?

+5
source share
2 answers

This is due to the file locking mechanism in java. Make sure you close the buffering streams such as BufferedReader, BufferedInputStream in this file when it was done.

+9
source

, , . , - :

public void createFile(String path)
{
    File file = new File(path);
    file.createNewFile();
    file = null
}

, , . FileReader FileWriter. null, . , .

-3

All Articles