Java Directory Create mkdirs(File file)

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

Description

Check and create missing parent directories for the given file.

License

Open Source License

Parameter

Parameter Description
file The file to check and create the missing parent directories for.

Exception

Parameter Description
IOException If the given file is actually not a file or if creating parentdirectories fails.

Declaration

private static void mkdirs(File file) throws IOException 

Method Source Code

//package com.java2s;
/*/*from   ww  w . j ava2s.c o  m*/
 * net/balusc/util/FileUtil.java
 *
 * Copyright (C) 2007 BalusC
 *
 * This program is free software: you can redistribute it and/or modify it under the terms of the
 * GNU Lesser General Public License as published by the Free Software Foundation, either version 3
 * of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License along with this library.
 * If not, see <http://www.gnu.org/licenses/>.
 */

import java.io.File;

import java.io.IOException;

public class Main {
    /**
     * Check and create missing parent directories for the given file.
     * @param file The file to check and create the missing parent directories for.
     * @throws IOException If the given file is actually not a file or if creating parent
     * directories fails.
     */
    private static void mkdirs(File file) throws IOException {
        if (file.exists() && !file.isFile()) {
            throw new IOException("File " + file.getPath() + " is actually not a file.");
        }
        File parentFile = file.getParentFile();
        if (!parentFile.exists() && !parentFile.mkdirs()) {
            throw new IOException("Creating directories " + parentFile.getPath() + " failed.");
        }
    }
}

Related

  1. mkDirs(File f)
  2. mkdirs(File f)
  3. mkdirs(File f)
  4. mkdirs(File file)
  5. mkdirs(File file)
  6. mkdirs(File file)
  7. mkdirs(File file)
  8. mkdirs(File file)
  9. mkdirs(File file)