Java Read Text File by BufferedReader, Java 7,Java 8

JavaSampleApproach will guide you how to read a text file by many approaches: BufferedReader, Java7 and Java8 with Java Read Text File

Note: input.txt file with content

I. Java Read Text File with Classis Approach – BufferedReader


II. Java 7
1. try-with-resources Statement

BufferedReader implements java.lang.AutoCloseable, so we can use it with try-with-resources statement of Java 7 with a shorter and clear sourcecode:

2. Files.readAllLines

For a small file, we can use Files.readAllLines to load all lines of file into memory then processing it. But we must be carefully to use it with a large file beacause of memory issues.

III. Java 8
1. Read File with Stream

2. Read & Process each line of a File by Stream, Filter, and Map functions


IV. Sourcecode


By grokonez | December 28, 2016.

Last updated on June 4, 2017.

Related Posts

Got Something To Say:

Your email address will not be published. Required fields are marked *