FTPClient中使用retrieveFileStream方法的正确姿势
方法说明
[接口文档地址](https://commons.apache.org/proper/commons-net/apidocs/org/apache/commons/net/ftp/FTPClient.html)
public InputStream retrieveFileStream(String remote) throws IOException {
return this._retrieveFileStream(FTPCmd.RETR.getCommand(), remote);
}
使用示例
public List<File> getFile() {
FtpUtil ftpUtil = new FtpUtil(ftpProperty);
String remotePath = "test";
List<File> files = Lists.newArrayList();
FTPFile[] ftpFiles = ftpUtil.listFiles(remotePath);
for (FTPFile ftpFile : ftpFiles) {
ftpUtil.changeWorkingDirectory(remotePath);
String name = ftpFile.getName();
log.info(name);
InputStream inputStream = ftpUtil.retrieveFileStream(name);
log.info("inputStream:{}", inputStream);
File file = new File(name);
File file1 = FileUtil.writeFromStream(inputStream, file);
files.add(file1);
try {
inputStream.close();
ftpUtil.completePendingCommand();
} catch (IOException e) {
e.printStackTrace();
}
}
return files;
}