Here you can find the source of forceMkdir(File directory)
Parameter | Description |
---|---|
directory | directory to create, must not be <code>null</code> |
Parameter | Description |
---|---|
NullPointerException | if the directory is <code>null</code> |
IOException | if the directory cannot be created |
public static void forceMkdir(File directory) throws IOException
//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); } } } }