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