gpt4 book ai didi

java - 尝试从 VFS FileObject 获取 ContentInfo 时出现 NullPointer

转载 作者:太空宇宙 更新时间:2023-11-04 07:39:21 24 4
gpt4 key购买 nike

我成功地使用 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):

https://issues.apache.org/jira/browse/VFS-427

关于java - 尝试从 VFS FileObject 获取 ContentInfo 时出现 NullPointer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16302826/

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