Enrol to start learning
Reading is open to everyone. Enrolling is free, and it is what unlocks the audio lessons, practice tests and progress tracking.
13.4.1. FileReader and FileWriter
This section
Practice test
10 questions on this section. Wrong answers show you what to read again.
Sign up to take itWhole chapter
Revision test
Mixed questions from across the chapter. Your answers get marked.
Sign up to take itQuick
Flashcard drill
2 cards from this lesson. Good the night before a test.
Try these first
- 1.
What class do you use to write to a file in Java?
Hint
Think of the class that begins with 'File'.
- 2.
What do you call the value returned by the read() method when the end of file is reached?
Hint
This is a special integer value.
- 3.
What is the primary purpose of FileWriter in Java?
- To read from a file
- To write to a file
- To delete a file
Hint
Think about how we handle output in Java.
- 4.
True or False: FileReader can only read binary files.
- True
- False
Hint
Consider the type of data FileReader handles.
- 5.
Create a Java program that writes five lines of text to a file and then reads that file back to display the contents on the console.
Hint
Make sure to use \\n for new lines when writing.
- 6.
Handle a scenario where a file might not exist and gracefully catch the exception using FileReader.
Hint
Think about using a try-catch block for handling exceptions.
Exercises
Total Questions
2
Estimated Time
4 min
Passing Score
70%
Instructions
- Read each question carefully
- You can use hints if you need help
- Complete all questions before submitting
4 more questions available
Enrol freeQuiz
Total Questions
2
Estimated Time
4 min
Passing Score
70%
Instructions
- Read each question carefully
- You can use hints if you need help
- Complete all questions before submitting
Get your answers marked and your progress tracked
Enrol freeChallenge Problems
Total Questions
2
Estimated Time
4 min
Passing Score
70%
Instructions
- Read each question carefully
- You can use hints if you need help
- Complete all questions before submitting