How to create directory in java?

Directory creation in java.

How to create multiple directories in java?

class DirCreation 
   public static void main(String args[])

    // mkdir() function to create single directory.
    boolean success = (new File("singleDir")).mkdir();
    if (success) {
      System.out.println("Directory  created");

    // mkdirs() function to create multiple directories
    success = (new File("/dir1/dir2/dir2")).mkdirs();
    if (success) {
      System.out.println("Directories  created");

    }catch (Exception e){//Catch exception if any
      System.err.println("Error: " + e.getMessage());
Share on Google Plus

About Pranav

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment