Here you can find the source of mkdirs(File file)
Parameter | Description |
---|---|
file | The file to check and create the missing parent directories for. |
Parameter | Description |
---|---|
IOException | If the given file is actually not a file or if creating parentdirectories fails. |
private static void mkdirs(File file) throws IOException
//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."); } } }