Java mkdir makeDir(File dir)

Here you can find the source of makeDir(File dir)

Description

Make the given folder (and any parent folders), throws an IOException on failure.

License

Open Source License

Parameter

Parameter Description
dir the folder

Exception

Parameter Description
IOException an exception

Declaration

public static void makeDir(File dir) throws IOException 

Method Source Code

//package com.java2s;
/*  MonkeyTalk - a cross-platform functional testing tool
Copyright (C) 2012 Gorilla Logic, Inc.//from   www  . j  a  v  a 2s .  c o  m
    
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
    
This program 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 Affero General Public License for more details.
    
You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>. */

import java.io.File;

import java.io.IOException;

public class Main {
    /**
     * Make the given folder (and any parent folders), throws an {@link IOException} on failure.
     * 
     * @param dir
     *            the folder
     * @throws IOException
     */
    public static void makeDir(File dir) throws IOException {
        makeDir(dir, null);
    }

    /**
     * Make the given folder (and any parent folders), throws an {@link IOException} with the error
     * message on failure.
     * 
     * @param dir
     *            the folder
     * @param msg
     *            the error message
     * @throws IOException
     */
    public static void makeDir(File dir, String msg) throws IOException {
        if (dir == null) {
            throw new IOException((msg != null ? msg : "dir") + " is null");
        } else if (!dir.exists()) {
            boolean success = dir.mkdirs();
            if (!success) {
                throw new IOException(
                        "Failed to make " + (msg != null ? msg : "dir") + ": " + dir.getAbsolutePath());
            }
        } else if (!dir.isDirectory()) {
            throw new IOException((msg != null ? msg : "dir") + " not a folder: " + dir.getAbsolutePath());
        }
    }
}

Related

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