我正在使用 Apache Commons VFS2 API(2.0 版)对 FTP 或 SFTP 文件进行通用实现。在我们将虚拟目录作为 FTP 目的地之前,它一直运行良好。我得到 NullpointerException 试图从 FileObject 获取 OutputStream。
...
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);
...