我正在尝试使用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)
但服务器已启动并正在运行,并且能够浏览目录。
任何人都可以告诉我这个错误可能是什么原因,我错过了什么吗?
答案 0 :(得分:1)
考虑在FS2上实施一个简单的具体回购。 FS2是一个中间件api,它处理文件系统中所需的所有CRUD等操作,但可以相对容易地由任何持久性机制支持。
答案 1 :(得分:0)
HTTP似乎不支持LIST_CHILDREN:
fileObject.getFileSystem().hasCapability(Capability.LIST_CHILDREN)
会返回false
您使用的是什么版本的VFS?也许v2.0会有所帮助。文件说: http://commons.apache.org/vfs/filesystems.html
答案 2 :(得分:0)
与文档所说的相反,我认为这还没有实现。看看https://issues.apache.org/jira/browse/VFS-199