1. Learn
  2. /
  3. Courses
  4. /
  5. Input/Output and Streams in Java

Connected

Exercise

Handling Long Notes Efficiently

As users write longer notes, performance becomes essential. Java's buffered classes facilitate the efficient reading and writing of large chunks of text. In this exercise, you'll use BufferedReader and BufferedWriter to handle a note saved in "note.txt".

All the necessary packages from java.io have been imported for you.

Instructions

100 XP
  • Create an instance of BufferedWriter called bw by wrapping a FileWriter for the file named "note.txt".
  • Write the first line of text, "This is the first line", to the file. Then add a line break using the .newLine() method and write the second line of text, "This is the second line", to the file.
  • Create an instance of BufferedReader called br by wrapping a FileReader to read the file "note.txt".
  • Read the file line by line.