Process lines as a stream
BufferedReader and BufferedWriter put an in-memory array between your code and the real source, so thousands of tiny reads or writes become a few big ones. BufferedReader also gives you readLine() and lines(), the standard way to read text line by line.
Change the code and press Run (Ctrl+Enter). Try to predict the output first, then break it on purpose and read the error. Your edits are saved and match the lesson page.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Read "apple\n\nbanana\ncherry\n" with a BufferedReader and print how many lines there are, how many are blank, and the longest line.
Write a method void writeTable(Writer out, String[] names, int[] scores) that prints aligned rows with PrintWriter (names left-aligned in 8 characters, scores right-aligned in 4). Test it with a StringWriter and print the result.
Using BufferedReader.lines(), count the words in a multi-line string, ignoring blank lines and extra spaces.
Explain it without notes
Why is buffered I/O faster, and what exactly does the buffer save?
How does readLine() treat line terminators, empty lines and the last line?
What's the difference between flush() and close(), and why do output files end up empty?
When would you choose Scanner over BufferedReader, and what are its pitfalls?
Expected output
{Delhi=380, Pune=570}