Practice File Class - 21.1.2 | 21. Java I/O and NIO | Advanced Programming
K12 Students

Academics

AI-Powered learning for Grades 8–12, aligned with major Indian and international curricula.

Professionals

Professional Courses

Industry-relevant training in Business, Technology, and Design to help professionals and graduates upskill for real-world careers.

Games

Interactive Games

Fun, engaging games to boost memory, math fluency, typing speed, and English skills—perfect for learners of all ages.

Practice Questions

Test your understanding with targeted questions related to the topic.

Question 1

Easy

What method do you use to check if a file exists?

💡 Hint: Think about what checks for a file's presence.

Question 2

Easy

How do you create a new File object for 'myfile.txt'?

💡 Hint: Remember how we declare an object in Java.

Practice 4 more questions and get performance evaluation

Interactive Quizzes

Engage in quick quizzes to reinforce what you've learned and check your comprehension.

Question 1

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.

Question 2

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.

Solve 1 more question and get performance evaluation

Challenge Problems

Push your limits with challenges.

Question 1

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.

Question 2

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.

Challenge and get performance evaluation