Java mkdir forceMkdir(File directory)

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

Description

force Mkdir

License

Open Source License

Parameter

Parameter Description
directory a parameter

Exception

Parameter Description
IOException an exception

Declaration

public static void forceMkdir(File directory) throws IOException 

Method Source Code

//package com.java2s;
/**//from   w  w  w . j av a2s  .  c o  m
 * Distributed under GNU GENERAL PUBLIC LICENSE Version 3
 *
 * @author Dmitry.Bedrin@gmail.com
 */

import java.io.File;
import java.io.IOException;

public class Main {
    /**
     * @param directory
     * @throws IOException
     */
    public static void forceMkdir(File directory) throws IOException {
        if (directory.exists()) {
            if (directory.isFile()) {
                throw new IOException(
                        "File " + directory + " exists and is not a directory. Unable to create directory.");
            }
        } else {
            if (!directory.mkdirs()) {
                throw new IOException("Unable to create directory " + directory);
            }
        }
    }
}

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)