我正在使用Apache Commons VFS2 API(版本2.0)来实现FTP或SFTP文件的通用实现。在我们将虚拟目录作为FTP目标之前,它一直很有效。尝试从FileObject获取OutputStream时,我得到NullpointerException。
...
DefaultFileSystemManager fileSystemManager = new DefaultFileSystemManager();
fileSystemManager.addProvider("ftp", new FtpFileProvider());
FileObject remoteObject = fileSystemManager.resolveFile(<FTP_URL>, null);
FileObject tempObject = fileSystemManager.resolveFile(remoteObject, "ftpFile.txt");
if(!tempObject.exists()){
tempObject = fileSystemManager.createVirtualFileSystem(tempObject);
}
//No file created by above actions so below gives null
OutputStream outputStream = tempObject.getContent().getOutputStream();
IOUtils.copy(inputStream, outputStream);
...