Java Directory Create mkdirs(File dir)

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

Description

Ensures that the given directory exists (if not, it's created, including all the parent directories.)

License

Open Source License

Return

This method returns the 'dir' parameter so that the method call flows better.

Declaration

public static File mkdirs(File dir) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.*;

public class Main {
    /**/*  w w  w .  ja  v a2s . com*/
     * Ensures that the given directory exists (if not, it's created, including all the parent directories.)
     *
     * @return
     *      This method returns the 'dir' parameter so that the method call flows better.
     */
    public static File mkdirs(File dir) throws IOException {
        if (dir.mkdirs() || dir.exists())
            return dir;

        // following Ant <mkdir> task to avoid possible race condition.
        try {
            Thread.sleep(10);
        } catch (InterruptedException e) {
            // ignore
        }

        if (dir.mkdirs() || dir.exists())
            return dir;

        throw new IOException("Failed to create a directory at " + dir);
    }
}

Related

  1. mkdir(File file)
  2. mkdir(File parent, String... segments)
  3. mkdir(File parentDir, String name)
  4. mkdirs(File dir)
  5. mkdirs(File dir)
  6. mkdirs(File dir)
  7. mkdirs(File dir)
  8. mkdirs(File dir)
  9. mkdirs(File dir)