2

我正在尝试使用 Commons VFS 从 HTTP 服务器浏览和检索文件以实现目录浏览功能,请在我的代码片段下方找到,

try {
    StandardFileSystemManager manager = new StandardFileSystemManager();
    manager.addProvider("http", new HttpFileProvider());
    manager.setCacheStrategy(CacheStrategy.ON_CALL);
    manager.setFilesCache(new SoftRefFilesCache());
    FileObject fileObject = manager.resolveFile("http://localhost");
    System.out.println(fileObject.getChildren());
} catch (FileSystemException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

但是当我运行这段代码时,我得到以下异常,

org.apache.commons.vfs.FileSystemException: Could not list the contents of "http://localhost/" because it is not a folder.
at org.apache.commons.vfs.provider.AbstractFileObject.getChildren(AbstractFileObject.java:527)
at org.apache.commons.vfs.impl.DecoratedFileObject.getChildren(DecoratedFileObject.java:105)
at org.apache.commons.vfs.cache.OnCallRefreshFileObject.getChildren(OnCallRefreshFileObject.java:105)
at VFSClient.main(VFSClient.java:31)

但是服务器已启动并正在运行,并且能够浏览目录。

谁能告诉我这个错误的原因是什么,我错过了什么吗?

4

3 回答 3

1

考虑在FS2上实现一个简单的具体仓库。FS2 是一个中间件 api,它处理文件系统中需要的所有 CRUD 等操作,但可以相对容易地得到任何持久性机制的支持。

于 2012-08-13T00:52:54.893 回答
0

与文档所说的相反,我认为这还没有实现。看看https://issues.apache.org/jira/browse/VFS-199

于 2012-01-09T03:32:22.520 回答
0

HTTP seems not to support LIST_CHILDREN:

fileObject.getFileSystem().hasCapability(Capability.LIST_CHILDREN)

would return false

what version of VFS are you using? maybe v2.0 would help. The documentation says so: http://commons.apache.org/vfs/filesystems.html

于 2011-11-16T14:49:35.973 回答