我成功地使用VFS从HTTP、SFTP、FTP等下载文件。我需要获取文件的内容类型,但我遇到了一件奇怪的事情,我不确定为什么会发生这种情况。
FileObject file = vfs.resolveFile(uri) ;
FileContent content = remote.getContent();
InputStream source = content.getInputStream();
ByteArrayOutputStream target = new ByteArrayOutputStream();
copy(source, target);
content.getSize(); // HACK: Prevents null-pointer in next line
String type = content.getContentInfo().getContentType();如果我删除对getSize的调用,content.getContentInfo将返回null。为什么会这样呢?我是不是遗漏了什么?
发布于 2015-01-06 08:03:28
正如@Sam-Rad所写的,它在主干(即将到来的VFS 2.1)中得到了修复:
https://stackoverflow.com/questions/16302826
复制相似问题