Create a directory; all non-existent ancestor directories are automatically created - Java File Path IO

Java examples for File Path IO:Directory Create

Description

Create a directory; all non-existent ancestor directories are automatically created

Demo Code

import java.io.File;

public class Main {
  public static void main(String[] args) throws Exception {
    // Create a directory; all ancestor directories must exist
    boolean success = (new File("directoryName")).mkdir();
    if (!success) {
      // Directory creation failed
    }/*from w  ww .j av a 2s  .c  om*/


    success = (new File("directoryName")).mkdirs();
    if (!success) {
      // Directory creation failed
    }
  }
}

Related Tutorials