Menu
Coddy logo textTech

Extras

Lesson 8 of 11 in Coddy's File Handling in Java course.

Before moving on to the challenges, there are some last important operations.

To check if a file exists, you can use exists() method:

File fileObj = new File("file.txt");
if (fileObj.exists()) {
	System.out.println("file.txt exists!");
} else {
	System.out.println("file.txt not exists.");
}

Another two methods:

  • mkdir() - Creates a directory.
  • list() - Returns an array of the files in the directory (String[]).
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

Try it yourself

This lesson doesn't include a code challenge.

All lessons in File Handling in Java