通过 HTTP 使用 Commons-VFS
我正在尝试使用 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)
但是服务器已启动并正在运行并且正在运行能够浏览目录。
谁能告诉我这个错误的原因是什么,我错过了什么吗?
I am trying to browse and retrieve files from an HTTP server using the Commons VFS to implement the directory browsing functionality, find below my code snippet,
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();
}
But when i run this code i get the following exception,
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)
But the server is up and running and am able to browse the directories.
Can anyone tell me what could be reason for this error, am I missing something ??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
考虑在 FS2 上实现一个简单的具体存储库。 FS2 是一个中间件 API,可以处理文件系统中所需的所有 CRUD 等操作,但可以相对轻松地由任何持久性机制支持。
Consider implementing a simple concrete repo on FS2. FS2 is a middleware api that handles all the CRUD, etc operations you need in a filesystem but can be backed by any persistence mechanism relatively easily.
HTTP 似乎不支持 LIST_CHILDREN:
会返回
false
您使用的 VFS 版本是什么?也许 v2.0 会有所帮助。文档是这样说的:
http://commons.apache.org/vfs/filesystems.html
HTTP seems not to support 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
与文档所述相反,我认为这尚未实现。看看 https://issues.apache.org/jira/browse/VFS-199
Contrary to what the documentation says, I don't think this is implemented yet. Take a look at https://issues.apache.org/jira/browse/VFS-199