Here you can find the source of mkdirs(File directory)
Parameter | Description |
---|---|
directory | the directory to create |
Parameter | Description |
---|---|
IOException | when there is a problem creating the directory |
true
if the directory was created, false
if it existed already.
public static boolean mkdirs(File directory) throws IOException
//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; } }