我正在尝试使用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)但是服务器已经启动并运行,并且能够浏览目录。
谁能告诉我这个错误的原因是什么,我是不是遗漏了什么?
发布于 2012-08-13 08:52:55
考虑在FS2上实现一个简单的具体存储库。FS2是一个中间件api,它处理文件系统中需要的所有CRUD等操作,但可以相对容易地由任何持久性机制支持。
发布于 2011-11-16 22:49:36
HTTP似乎不支持LIST_CHILDREN:
fileObject.getFileSystem().hasCapability(Capability.LIST_CHILDREN)将返回false
您使用的是什么版本的VFS?也许v2.0会有所帮助。文档是这样说的:http://commons.apache.org/vfs/filesystems.html
发布于 2012-01-09 11:32:23
与文档所说的相反,我认为这还没有实现。看一看https://issues.apache.org/jira/browse/VFS-199
https://stackoverflow.com/questions/6999300
复制相似问题