Java 8 Stream – Read a file line by line
In Java 8, you can use Files.lines to read file as Stream. A new method lines() has been added since 1.8, it lets BufferedReader returns content as Stream.
Favourite tutorials for developers
In Java 8, you can use Files.lines to read file as Stream. A new method lines() has been added since 1.8, it lets BufferedReader returns content as Stream.
This article explains the Java 8 Stream.flatMap and how to use it. In Java 8, we can use the flatMap to convert the above 2 levels Stream into one Stream…
Long live the Scanner class, a few examples for self-reference.
This article shows how to convert a file into a hexadecimal (hex) representative format. The idea is to read the file into an InputStream and uses String.format(%X) to convert each…
This article shows a few ways to save a byte into a file. For JDK 1.7 and above, the NIO Files.write is the simplest solution to save byte to a…
In Java, we can use Files.readAllBytes(path) to convert a File object into a byte. Before Java 7, we can initiate a new byte with a predefined size (same with the…
In Java, we use FileInputStream to read bytes from a file, such as an image file or binary file. The FileInputStream.read() reads a byte at a time, and it will…
Here is another example to show how to read a file in Java with BufferedInputStream and DataInputStream classes. The readLine() from the type DataInputStream is deprecated. Sun officially announced this…
In Java, the InputStreamReader accepts a charset to decode the byte streams into character streams. We can pass a StandardCharsets.UTF_8 into the InputStreamReader constructor to read data from a UTF-8…
This article focus on a few of the commonly used methods to read a file in Java. 1 - Files.lines, return a Stream (Java 8), 2 - Files.readString, returns a…