Java mkdir forceMkdir(File directory)

Here you can find the source of forceMkdir(File directory)

Description

Make a directory, including any necessary but nonexistent parent directories.

License

Open Source License

Parameter

Parameter Description
directory directory to create, must not be <code>null</code>

Exception

Parameter Description
NullPointerException if the directory is <code>null</code>
IOException if the directory cannot be created

Declaration

public static void forceMkdir(File directory) throws IOException 

Method Source Code


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

import java.io.IOException;

public class Main {
    /**/*w w w  . ja v  a  2s.  c  o  m*/
     * Make a directory, including any necessary but nonexistent parent
     * directories. If there already exists a file with specified name or
     * the directory cannot be created then an exception is thrown.
     *
     * @param directory  directory to create, must not be <code>null</code>
     * @throws NullPointerException if the directory is <code>null</code>
     * @throws IOException if the directory cannot be created
     */
    public static void forceMkdir(File directory) throws IOException {
        if (directory.exists()) {
            if (directory.isFile()) {
                String message = "File " + directory + " exists and is "
                        + "not a directory. Unable to create directory.";
                throw new IOException(message);
            }
        } else {
            if (!directory.mkdirs()) {
                String message = "Unable to create directory " + directory;
                throw new IOException(message);
            }
        }
    }
}

Related

  1. forceMkdir(File dir)
  2. forceMkdir(File directory)
  3. forceMkdir(File directory)
  4. forceMkdir(String filePath)
  5. forceMkdirs(File file)
  6. makeDir(File dir)
  7. makeDir(File dir)