How to create a directory in java

0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Filament.io 0 Flares ×

Java File class provides methods to create directory. Two important methods are mkdir and mkdirs. It is important to understand these two methods and pay attention to the return values to confirm that the operation is successful.

Method mkdir()

Creates the directory named by this abstract pathname. The boolean return value indicates whether the operation is successful.

Method mkdirs()

This is a very useful method as it can create parent directories if not existing. It can create directory named by the abstract path name supplied to the method, including any necessary but nonexistent parent directories. Here again pay attention to the returned Boolean value to confirm that the operation is successful.