The code refers to the following articles (not yet published):
- English: Java BufferedReader
- German: Java BufferedReader
Most examples read the small log file files/server.log. Every class with a main() method in eu.happycoders.bufferedreader is one chapter of the article and prints the outputs shown there. Run one from the repository root with java -cp target/classes eu.happycoders.bufferedreader.<ClassName> after mvn compile. Files the examples create go into target/.
Intro– reads the log file line by lineCh1Creating–Files.newBufferedReader(),FileReader,InputStreamReaderaround aGZIPInputStream, an own buffer size, and a Latin-1 file read as UTF-8Ch2ReadLine– line terminators, empty lines, and the end of the inputCh3Lines–lines()withfilter()andgroupingBy(), anUncheckedIOExceptionwhile streaming, andFiles.lines()Ch4ReadAll–readAllLines()andreadAllAsString()(Java 25), also after areadLine()Ch5Characters–read()andread(char[], int, int)Ch6MarkReset– an optional header line withmark()andreset(), andskip()Ch6Ready–ready()returnsfalse, yet the nextreadLine()returns a lineCh7Console– reading lines fromSystem.inwith the charset fromstdin.encoding(Java 25)Ch7Readln–IO.readln()(Java 25)Ch8Scanner– tokens withScannerand withsplit(), and how both classes report anIOExceptionCh9Closing– closing theBufferedReadercloses the reader inside itCh10Mistakes– callingreadLine()twice per loop iteration
The package eu.happycoders.bufferedreader.benchmark contains the JMH benchmarks of the article's performance section:
ReadBenchmark– reading a 100,000,000-byte UTF-8 text file withInputStreamReader,FileReader, andBufferedReader(read(),read(char[]),readLine(),lines(),readAllLines()), and withScanner.nextLine()BufferSizeBenchmark–readLine()with buffer sizes from 256 to 1,048,576 charactersReadCallCounter– not JMH: counts how often theInputStreamReaderreads from the file when aBufferedReaderreads it line by line, for buffer sizes from 256 to 1,048,576 characters; the count is the same for every sizeDecoderWarmupCheck– not JMH: decodes the test file with anInputStreamReaderin blocks of one size after warming the JVM up with another, one JVM per call; it shows that the speed depends on the warm-up block size, not on the measured one (the command is in the class comment)
The first run creates the test file target/benchmark-input.txt from a fixed seed, so every machine reads the same file. Build and run:
mvn package
java -jar target/benchmarks.jar
The complete run takes about 15 minutes. Close other applications while it runs. The results of the article's run are in results/apple-m5-pro/.
Stay up-to-date with the latest Java features with this free PDF Cheat Sheet!
- Avoid lengthy research with this concise overview of all Java versions from Java 10 to Java 27.
- Discover the innovative features of each new Java version, summarized on a single page.
- Impress your team with your up-to-date knowledge of the latest Java version.
👉 Download the free Java Versions PDF
(Hier geht's zur deutschen Version → Java-Versionen PDF)
With this free 1-page PDF cheat sheet, you'll always have the 7 most important complexity classes at a glance.
- Always choose the most efficient data structures and thus increase the performance of your applications.
- Be prepared for technical interviews and confidently present your algorithm knowledge.
- Become a sought-after problem solver and be known for systematically tackling complex problems.
👉 Download the free Big O Cheat Sheet
(Hier geht's zur deutschen Version → O-Notation Cheat Sheet)
👉 Want to stay on top of modern Java? Sign up for the HappyCoders newsletter – Modern Java: new versions & features, performance, and JVM insights – once a month.
(Hier geht's zur deutschen Version → HappyCoders-Newsletter deutsch)
🇩🇪 An alle Java-Entwickler:innen, die durch fundierte Kenntnisse über Datenstrukturen besseren Code schreiben wollen
Trage dich jetzt unverbindlich auf die Warteliste von „Mastering Data Structures in Java“ ein, und erhalte das beste Angebot!


