AllRounder.ai
Chapters in this course

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.

Enrol free

13.4.3. File Class

  • This section

    Practice test

    11 questions on this section. Wrong answers show you what to read again.

    Sign up to take it
  • Whole chapter

    Revision test

    Mixed questions from across the chapter. Your answers get marked.

    Sign up to take it
  • Quick

    Flashcard drill

    4 cards from this lesson. Good the night before a test.

Try these first

  1. 1.

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

    Hint

    Think about how you would confirm presence.

  2. 2.

    How would you create a new file named 'test.txt'?

    Hint

    Consider the sequence of creating a file.

  3. 3.

    What does the exists() method do?

    • Checks if a file can be read
    • Checks if a file exists
    • Checks file size
    Hint

    Reflect on the importance of confirming a file's presence.

  4. 4.

    True or False: The length() method returns the last modified date of the file.

    • True
    • False
    Hint

    Consider what 'length' implies in context.

  5. 5.

    Design a Java program that checks if a specified file exists and deletes it. If it does not exist, print an appropriate message.

    Hint

    Remember to handle potential IOException for the delete operation.

  6. 6.

    Create a script that logs the sizes of multiple files in a directory and outputs them to a text file.

    Hint

    Utilize FileWriter for output and ensure you close it after writing.

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 free

Quiz

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 free

Challenge 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