I would like to hava a static Path property to be scanned for children files, this Path references a zip file and I can't close it because it will be referenced randomly. At some points I need to write into the zip file. The problem is I don't want to close the file system, because the Path property need to be open for future reading, and if I don't close it I can't see the written changes. If I try to create another filesystem referencing the same path I get FileSystemAlreadyExistsException. I could close the fs after writing and then open it again, but some one could try to read the Path at this moment. There is a workaround ? Why don't I need to close the default FileSystem to see the written files and I do need with the zip FileSystem?
public static void copyTree(final Path source, final Path targetPath) throws IOException {
FileSystem fs = FileSystems.getFileSystem(targetPath.toUri());
Files.walkFileTree(source, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
Files.copy(dir, targetPath, StandardCopyOption.REPLACE_EXISTING);
return super.preVisitDirectory(dir, attrs);
}
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
Files.copy(file, targetPath, StandardCopyOption.REPLACE_EXISTING);
return super.visitFile(file, attrs);
}
});
//if I don't close the FileSystem here the changes won't appear.
fs.close();
}