【发布时间】:2021-04-19 20:36:05
【问题描述】:
我是 Commons VFS 的新手,正在尝试了解如何打开嵌套存档。我在处理此问题的源代码中找到了一个示例。此测试通过。
@Test
void testTGZ() throws Exception {
FileSystemManager fsManager = VFS.getManager();
String uri = "tgz:file:///c:/data/nested.tgz!/test.tgz";
FileObject archive = fsManager.resolveFile(uri);
FileObject nestedFs = fsManager.createFileSystem(archive);
// List the children of the archive file
FileObject[] children = nestedFs.getChildren();
for (FileObject child : children) {
System.out.println(child.getURI());
}
}
而这个失败了
org.apache.commons.vfs2.FileSystemException: Could not find a file provider that can handle file "tgz:file:///C:/data/nested.tar.gz!/test.tar.gz".
@Test
void testTarGZ() throws Exception {
FileSystemManager fsManager = VFS.getManager();
String uri = "tgz:file:///c:/data/nested.tar.gz!/test.tar.gz";
FileObject archive = fsManager.resolveFile(uri);
FileObject nestedFs = fsManager.createFileSystem(archive);
// List the children of the archive file
FileObject[] children = nestedFs.getChildren();
for (FileObject child : children) {
System.out.println(child.getURI());
}
}
除了名称之外,这些文件都相同,那么为什么一个可以工作而另一个不行呢?我做错了什么?
【问题讨论】:
-
这两个文件是如何创建的?使用
tar zcf foo.tgz inputfilenames创建的文件与使用tar cf foo.tar inputfilenames; gzip foo.tar创建的文件不同。会不会是 Commons VFS 只处理一个而不处理另一个? -
@JimGarrison 你可能是对的。我必须检查一下。