Created
June 17, 2021 08:44
-
-
Save GioF71/fb869130ae1483bf3ef4412106924e73 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static <T> List<T> readFile( | |
String fileName, | |
Supplier<List<T>> listSupplier, | |
Function<String, T> converter) throws IOException { | |
List<T> list = listSupplier.get(); | |
FileInputStream inputStream = null; | |
try { | |
ClassLoader classLoader = Puzzle01.class.getClassLoader(); | |
File file = new File(classLoader.getResource(fileName).getFile()); | |
inputStream = new FileInputStream(file); | |
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); | |
String line; | |
while ((line = reader.readLine()) != null) { | |
list.add(converter.apply(line)); | |
} | |
reader.close(); | |
} finally { | |
inputStream.close(); | |
} | |
return list; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment