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.
21.1.2. File Class
This section
Practice test
9 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
4 cards from this lesson. Good the night before a test.
Try these first
- 1.
What method do you use to check if a file exists?
Hint
Think about what checks for a file's presence.
- 2.
How do you create a new File object for 'myfile.txt'?
Hint
Remember how we declare an object in Java.
- 3.
What does the method exists() in the File class do?
- Checks the file size
- Checks if the file is readable
- Checks if the file exists
Hint
Focus on the purpose of the method.
- 4.
True or False: The File class can only represent files, not directories.
- True
- False
Hint
Consider what else you can represent with the File class.
- 5.
Write a Java program that prompts the user for a file name, checks if it exists, and either displays the full path or an error message.
Hint
Use methods from the File class to accomplish this task.
- 6.
Explain how the File class can be used to check file permissions apart from checking existence.
Hint
Think about the various interactions you might need with files.
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
2 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
1 more question available
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