Java Language Reading files


Example

Files can be read byte- and line-wise using the Files class.

Path p2 = Paths.get(URI.create("file:///home/testuser/File.txt"));
byte[] content = Files.readAllBytes(p2);
List<String> linesOfContent = Files.readAllLines(p2);

Files.readAllLines() optionally takes a charset as parameter (default is StandardCharsets.UTF_8):

List<String> linesOfContent = Files.readAllLines(p2, StandardCharsets.ISO_8859_1);