我成功地使用 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。为什么是这样?我错过了什么吗?
最佳答案
正如 @Sam-Rad 所写,它已在主干中修复(即将推出的 VFS 2.1):
关于java - 尝试从 VFS FileObject 获取 ContentInfo 时出现 NullPointer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16302826/