As @Sam-Rad wrote, it is fixed in trunk (upcoming VFS 2.1):
NullPointer when trying to get ContentInfo from VFS FileObject
-
13-04-2022 - |
سؤال
I'm successfully using VFS to download files from HTTP, SFTP, FTP, etc. I need to get the content type of the file and I've run into a strange thing that I'm not sure why is happening.
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();
If I remove the call to getSize
, content.getContentInfo
will return null. Why is this? Am I missing something?
المحلول
لا تنتمي إلى StackOverflow