Java Directory Create mkdirs(File directory)

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

Description

mkdirs

License

Open Source License

Declaration

public static boolean mkdirs(File directory) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2010-2011 Sonatype, Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 *   http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/

import java.io.File;

import java.io.IOException;

public class Main {
    public static boolean mkdirs(File directory) {
        if (directory == null) {
            return false;
        }/*  www . jav  a 2 s  .c om*/

        if (directory.exists()) {
            return false;
        }
        if (directory.mkdir()) {
            return true;
        }

        File canonDir = null;
        try {
            canonDir = directory.getCanonicalFile();
        } catch (IOException e) {
            return false;
        }

        File parentDir = canonDir.getParentFile();
        return (parentDir != null && (mkdirs(parentDir) || parentDir.exists()) && canonDir.mkdir());
    }
}

Related

  1. mkdirs(File dir)
  2. mkdirs(File dir)
  3. mkdirs(File dir)
  4. mkdirs(File directory)
  5. mkdirs(File directory)
  6. mkdirs(File directory, String string)
  7. mkdirs(File dirs)
  8. mkdirs(File dumpFile)
  9. mkdirs(File f)