我正在尝试使用 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)
但是服务器已启动并正在运行,并且能够浏览目录。
谁能告诉我这个错误的原因是什么,我错过了什么吗?