Java Create Directory mkdir(String directory)

Here you can find the source of mkdir(String directory)

Description

This method creates the specified directory.

License

Open Source License

Parameter

Parameter Description
directory The directory to create.

Exception

Parameter Description
IOException if I/O exception

Declaration

public static void mkdir(String directory) throws IOException 

Method Source Code


//package com.java2s;
import java.io.File;

import java.io.IOException;

public class Main {
    /**//from   ww w  .  j  av  a 2s  . co m
     * This method creates the specified directory.
     * 
     * @param directory The directory to create.
     * @throws IOException if I/O exception
     */
    public static void mkdir(String directory) throws IOException {
        File f = new File(directory);
        if (f.exists()) {
            if (f.isFile()) {
                throw new IOException("Error creating directory:" + directory); //$NON-NLS-1$
            }
        } else {
            if (!f.mkdirs()) {
                throw new IOException("Error creating directory:" + directory); //$NON-NLS-1$
            }
        }
    }
}

Related

  1. mkDir(final String folderPath)
  2. mkDir(String destDir, String dirName)
  3. mkdir(String dir)
  4. mkdir(String dir, String file)
  5. mkdir(String dir_str)
  6. mkdir(String directory)
  7. mkdir(String directory)
  8. mkDir(String DirectoryName)
  9. mkdir(String directoryName)