Here you can find the source of makeDir(File dir)
Parameter | Description |
---|---|
dir | the folder |
Parameter | Description |
---|---|
IOException | an exception |
public static void makeDir(File dir) throws IOException
//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()); } } }