예:
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의 새로운 기능