Opened file in Java and in Windows file cannot be accesed, even Java is not using file anymore

StackOverflow https://stackoverflow.com/questions/18943430

  •  29-06-2022
  •  | 
  •  

Question

I have directory where I will look for ZIP files and then I will extract files from those ZIP files with TrueZIP 7. My problem is that when I have my application running, I cannot delete/edit file while application is running in Windows. I don't understand why this is happening, because when I'm accessing file in Windows my application is not doing anything with files, so why these files are locked to my Java app?

I have following code:

Path dir = FileSystems.getDefault().getPath(directory);
try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) {
    for (Path file : stream) {
        // do something with file
    }
} catch (IOException | DirectoryIteratorException x) {
    System.err.println(x);
}
// Why those files are still locked to my app even when execution is here ???
Was it helpful?

Solution

I forgot to call unmount :

TVFS.umount();

Now I can delete/edit files.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top