Java Directory Create mkdirs(File file)

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

Description

A safer version of File.mkdirs, which works around a race in the 1.5 JDK where two VMs creating the same directory chain at the same time could end up in one VM failing to create a subdirectory.

License

Open Source License

Parameter

Parameter Description
file a parameter

Declaration

public static boolean mkdirs(File file) 

Method Source Code


//package com.java2s;
import java.io.File;

public class Main {
    /**/*w  ww .j  a  v  a  2  s .  c o  m*/
     * A safer version of File.mkdirs, which works around
     * a race in the 1.5 JDK where two VMs creating the same 
     * directory chain at the same time could end up in one
     * VM failing to create a subdirectory.
     * @param file
     */
    public static boolean mkdirs(File file) {
        final File parentFile = file.getAbsoluteFile().getParentFile();
        if (!parentFile.exists()) {
            mkdirs(parentFile);
        }
        //As long as someone successfully created the parent file
        //go ahead and create the child directory.
        if (parentFile.exists()) {
            return file.mkdir();
        } else {
            return false;
        }
    }
}

Related

  1. mkdirs(File file)
  2. mkdirs(File file)
  3. mkdirs(File file)
  4. mkdirs(File file)
  5. mkdirs(File file)
  6. mkdirs(File file)
  7. mkdirs(File folder)