ReadLineUtil删除临时文件

This commit is contained in:
qiaoqinzheng 2023-10-24 10:57:17 +08:00
parent e52e27cebc
commit 52c8d04a76

View File

@ -44,6 +44,7 @@ public class ReadLineUtil {
throw new RuntimeException("ftp连接失败!");
}
InputStream iStream = null;
File file = null;
try {
ftpClient.enterLocalPassiveMode();
String fileName = filePath.substring(filePath.lastIndexOf(StringPool.SLASH) + 1);
@ -63,7 +64,7 @@ public class ReadLineUtil {
//读取ftp文件的输入流
iStream=ftpClient.retrieveFileStream(ftpFile.getName());
//声明一个临时文件
File file = File.createTempFile("betaGamma", null);
file = File.createTempFile("betaGamma", null);
//将ftp文件的输入流复制给临时文件
FileUtils.copyInputStreamToFile(iStream, file);
List<String> allLines = FileUtils.readLines(file, encoding);
@ -93,6 +94,9 @@ public class ReadLineUtil {
if (Objects.nonNull(iStream)){
iStream.close();
}
if (Objects.nonNull(file)) {
file.delete();
}
} catch (IOException e) {
throw new RuntimeException(e);
}