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

Connected

Exercise

Writing and Reading a Note

Now that you can create files, it's time to add real content. You'll write a short note to a text file and then read it back to confirm it was saved correctly. This is a core feature of any note-taking application.

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

Instructions

100 XP
  • Write the text "Start from the beginning" to a file named "note.txt".
  • Create a FileWriter in append mode for "note.txt" as fwAppendMode.
  • Add the text " Add to the end" to the file without overwriting its content.
  • Use FileReader to read the content of the file and display it on the console, one character at a time.