我發現了一個例外,而使用Java NIO走一個zip文件的VFS(虛擬文件系統)的文件樹走一個zip中的文件樹,這裏是我的代碼:nosuchfileexception同時使用Java NIO
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;
}
});
}
該例外說,一個文件不存在,但我已經解壓檔案(zip),並且文件在那裏......任何想法爲什麼?
這裏是個例外:
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:代碼的工作,但它與某些文件
有沒有對它失敗的文件有任何模式?總是xlsm?在zip文件中使用的任何密碼? –
不,我至少可以看到... – Ordiel
你有沒有想過這個?我也很難過。來自http://stackoverflow.com/questions/14436032/why-is-java-7-files-walkfiletree-throwing-exception-on-encountering-a-tar-file-o評論我目前的猜測是它調用某種本地窗口getAttributes *錯誤*或者什麼... jdk bug?剛剛在Windows上的JDK錯誤?你在窗戶上嗎? – rogerdpack