O'Reilly logo

Java™ Phrasebook by Timothy Fisher

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Determining if a File or Directory Exists

boolean exists = (new File("filename")).exists();
											if (exists) {
											// File or directory exists
											}
											else {
											// File or directory does not exist
											}

In this phrase, we use the exists() method on the File object to determine if the file or directory represented by the File object exists. The exists() method will return true if the file or directory exists, otherwise it will return false.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required