示例:
static List<String> readFileAndTrim(Path path) throws IOException {
List<String> lines = Files.readAllLines(path);
return lines.stream().map(String::trim).toList();
}
static List<String> readFileAndTrim(String path) throws IOException {
Path p = Path.of(path);
List<String> lines = Files.readAllLines(p);
return lines.stream().map(String::trim).toList();
}
在这里,第二个方法与第一个方法非常相似,第一个方法可以在其实现中重用。
应用该快速修复后,结果将如下所示:
static List<String> readFileAndTrim(Path path) throws IOException {
List<String> lines = Files.readAllLines(path);
return lines.stream().map(String::trim).toList();
}
static List<String> readFileAndTrim(String path) throws IOException {
Path p = Path.of(path);
return readFileAndTrim(p);
}
2024.1 最新变化