gpt4 book ai didi

java - 通过 HTTP 使用 Commons-VFS

转载 作者:可可西里 更新时间:2023-11-01 16:39:22 25 4
gpt4 key购买 nike

我正在尝试使用 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)

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

谁能告诉我这个错误的原因是什么,我是不是遗漏了什么??

最佳答案

考虑在 FS2 上实现一个简单的具体 repo 协议(protocol). FS2 是一种中间件 API,可处理您在文件系统中需要的所有 CRUD 等操作,但可以相对轻松地由任何持久性机制提供支持。

关于java - 通过 HTTP 使用 Commons-VFS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6999300/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com