Java Directory Create mkdirs(File directory)

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

Description

Creates a new directory.

License

Apache License

Parameter

Parameter Description
directory the directory to create

Exception

Parameter Description
IOException when there is a problem creating the directory

Return

true if the directory was created, false if it existed already.

Declaration

public static boolean mkdirs(File directory) throws IOException 

Method Source Code

//package com.java2s;
/*/*w w w . j  a v a  2  s. co m*/
 * Copyright (c) 2012 Yan Pujante
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

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

public class Main {
    /**
     * Creates a new directory. This method creates automatically all the parent directories if
     * necesary. Contrary to <code>File.mkdirs</code>, this method will fail if the directory cannot
     * be created. The returned value is also different in meaning: <code>false</code> means that the
     * directory was not created because it already existed as opposed to it was not created because
     * we don't know.
     *
     * @param directory the directory to create
     * @return <code>true</code> if the directory was created, <code>false</code> if it existed
     *         already.
     * @throws IOException when there is a problem creating the directory
     */
    public static boolean mkdirs(File directory) throws IOException {
        if (directory.exists())
            return false;

        if (!directory.mkdirs())
            throw new IOException("cannot create the directory: " + directory);

        return true;
    }
}

Related

  1. mkdirs(File dir)
  2. mkdirs(File dir)
  3. mkdirs(File dir)
  4. mkdirs(File dir)
  5. mkdirs(File dir)
  6. mkdirs(File directory)
  7. mkdirs(File directory)
  8. mkdirs(File directory, String string)
  9. mkdirs(File dirs)