Java Create Directory mkdir(String dir_str)

Here you can find the source of mkdir(String dir_str)

Description

A simple method that creates a directory if it does not exists.

License

Open Source License

Parameter

Parameter Description
dir_str The path of the directory.

Return

A boolean value that should signify the directory's existence. If FALSE, you should assume that there was an issue while creating it.

Declaration

public static boolean mkdir(String dir_str) 

Method Source Code


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

import java.io.File;

public class Main {
    /**/*w  ww .  jav a2s .c om*/
     * A simple method that creates a directory if it does not exists.
     *
     * @param dir_str The path of the directory.
     * @return A boolean value that should signify the directory's existence. If FALSE, you should assume that there was an issue while creating it.
     */
    public static boolean mkdir(String dir_str) {
        File dir = new File(dir_str);
        if (!dir.exists()) {
            try {
                dir.mkdir();
                return true;
            } catch (SecurityException se) {
                se.printStackTrace();
                return false;
            }
        } else {
            return true;
        }
    }
}

Related

  1. mkdir(final String directory)
  2. mkDir(final String folderPath)
  3. mkDir(String destDir, String dirName)
  4. mkdir(String dir)
  5. mkdir(String dir, String file)
  6. mkdir(String directory)
  7. mkdir(String directory)
  8. mkdir(String directory)
  9. mkDir(String DirectoryName)