Java Directory Create mkdir(File dir)

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

Description

Creates the given directory.

License

Apache License

Parameter

Parameter Description
dir the directory to be created.

Exception

Parameter Description
IOException if the file could not be created.

Declaration

public static void mkdir(File dir) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.*;

public class Main {
    /**//from  w w w  . j a va  2 s  .com
     * Creates the given directory.
     *
     * @param dir the directory to be created.
     * @throws IOException if the file could not be created.
     * @see File#mkdir()
     */
    public static void mkdir(File dir) throws IOException {
        if (!dir.exists() || !dir.isDirectory()) {
            if (!dir.mkdir()) {
                throw new IOException("Failed to create directory " + dir);
            }
        }
    }

    /**
     * Return true or false based on whether the named file exists. */
    static public boolean exists(String filename) throws IOException {
        try {
            return (new File(filename)).exists();
        } catch (Throwable e) {
            throw toIOException(e);
        }
    }

    static IOException toIOException(Throwable e) {
        if (e instanceof IOException) {
            return (IOException) e;
        } else {
            return new IOException(e.getMessage());
        }
    }
}

Related

  1. mkdir(File d)
  2. mkdir(File dir)
  3. mkdir(File dir)
  4. mkdir(File dir)
  5. mkdir(File dir)