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

Creating a New Directory

boolean success = (new File("users/tim")).mkdir();

In this phrase, we use the mkdir() method of the File class to create a new directory. This method will return true if the directory is successfully created. If the directory cannot be created, the method returns false. The mkdir() method will only create a directory if all specified parent directories already exist. In the preceding phrase, the users directory must already exist for this execution of mkdir() to successfully create the users/tim directory.

A similar method will allow you to create an entire directory tree, including all parent directories, if they do not exist. This is the mkdirs() method on the File class. Here, we show an example using this method: ...

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