[ISSUE #9447] Avoiding possible resource leaks in InputStream (#9459)

This commit is contained in:
Xu Chengxin
2025-06-30 14:31:04 +08:00
committed by GitHub
parent d3d126e7d7
commit be67d61223
4 changed files with 64 additions and 66 deletions
@@ -101,17 +101,17 @@ public class DuplicateMessageInfo<T> {
if (bPrintLog) {
String logFileNameStr = "D:" + File.separator + "checkDuplicatedMessageInfo.txt";
File logFileNameFile = new File(logFileNameStr);
OutputStream out = new FileOutputStream(logFileNameFile, true);
try (OutputStream out = new FileOutputStream(logFileNameFile, true)) {
String strToWrite;
byte[] byteToWrite;
strToWrite = strBuilder + titleString;
for (int i = 0; i < msgListSize; i++)
strToWrite += strBQueue.get(i).toString() + "\r\n";
String strToWrite;
byte[] byteToWrite;
strToWrite = strBuilder + titleString;
for (int i = 0; i < msgListSize; i++)
strToWrite += strBQueue.get(i).toString() + "\r\n";
byteToWrite = strToWrite.getBytes(StandardCharsets.UTF_8);
out.write(byteToWrite);
out.close();
byteToWrite = strToWrite.getBytes(StandardCharsets.UTF_8);
out.write(byteToWrite);
}
}
}