I'm getting an exception while walking a file tree of a VFS (virtual file system) of a zip file using java nio, here is my code:
public static void list(String zipFilePath) throws IOException{
FileSystem fs = FileSystems.newFileSystem(Paths.get(zipFilePath), null);
Path startPath = fs.getPath("/");
Files.walkFileTree(startPath, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
System.out.println("Dir : " + dir);
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
System.out.println("\t->File : " + file);
return FileVisitResult.CONTINUE;
}
});
}
the exception says that a file does not exists, but I've decompress the archive (zip), and the file is there... any idea why?
here is the exception:
java.nio.file.NoSuchFileException: /Dir1/Dir2/Dir3/Dir4/ExcelFile.xlsm
at com.sun.nio.zipfs.ZipPath.getAttributes(ZipPath.java:657)
at com.sun.nio.zipfs.ZipFileSystemProvider.readAttributes(ZipFileSystemProvider.java:285)
at java.nio.file.Files.readAttributes(Files.java:1669)
at java.nio.file.FileTreeWalker.walk(FileTreeWalker.java:105)
at java.nio.file.FileTreeWalker.walk(FileTreeWalker.java:199)
at java.nio.file.FileTreeWalker.walk(FileTreeWalker.java:69)
at java.nio.file.Files.walkFileTree(Files.java:2585)
at java.nio.file.Files.walkFileTree(Files.java:2618)
BTW: The code DOES work, but it crash with certain files