我想问一些关于如何使这段代码更简单的提示
private void outputPatternList(String message) throws IOException {
try (BufferedWriter out = new BufferedWriter(new FileWriter(patternList, true))) {
out.write(message);
out.write("\n");
}
}
答案 0 :(得分:1)
您需要将代码重构为:
private void outputPatternList(List<String> lines) throws IOException {
StringBuilder builder = new StringBuilder();
for (String line : lines) {
builder.append(line).append("/n");
}
String message = builder.toString().trim();
try (BufferedWriter out = new BufferedWriter(new FileWriter(patternList, true))) {
out.write(message);
}
}