Example usage for java.io File mkdirs

List of usage examples for java.io File mkdirs

Introduction

In this page you can find the example usage for java.io File mkdirs.

Prototype

public boolean mkdirs() 

Source Link

Document

Creates the directory named by this abstract pathname, including any necessary but nonexistent parent directories.

Usage

From source file:Main.java

public static String createFile(String parent, String fileName) {
    File dir = new File(parent);
    if (!dir.exists()) {
        dir.mkdirs();
    }//from  w w w.  jav a  2  s . co m
    File file = new File(dir, fileName);
    return file.getAbsolutePath();
}

From source file:Main.java

static void createParentDirs(File file) {
    File dir = file.getParentFile();
    if (dir != null && !dir.exists() && !dir.mkdirs())
        throw new IllegalStateException("Couldnt create " + dir);
}

From source file:Main.java

public static final void IS_DIRECTORY_EXIST(String filePath) {
    File dir = new File(filePath);

    if (!dir.exists()) {
        dir.mkdirs();
    }// www . ja v  a 2s.  c om
}

From source file:Main.java

public static void ensureDirectoryExist(String path) {

    File sdkDir = new File(path);
    if (!sdkDir.exists()) {
        sdkDir.mkdirs();
    }//from ww w . j  av a 2  s. c  o  m
}

From source file:Main.java

public static File createFile(File destDir, String filename) {
    File file = new File(destDir, filename);
    File parent = file.getParentFile();
    if (parent != null)
        parent.mkdirs();
    return file;//from   w ww. j  ava2s  . co  m
}

From source file:Main.java

public static File getTempDir() {
    File ext = Environment.getExternalStorageDirectory();
    File tempDir = new File(ext, "aquery/temp");
    tempDir.mkdirs();
    if (!tempDir.exists() || !tempDir.canWrite()) {
        return null;
    }/* w  w  w.j a va 2s .c  om*/
    return tempDir;
}

From source file:Main.java

private static String creatDir(String dirPath) {
    File file = new File(dirPath);
    if (!file.exists()) {
        file.mkdirs();
    }//from   ww  w  .j a  v  a2s. c  o  m
    return dirPath;
}

From source file:Main.java

public static File obtainDirF(String path) {
    File file = new File(path);
    if (!file.exists()) {
        file.mkdirs();
    }//from   w ww  .ja  v  a 2s .c  o m
    return file;
}

From source file:Main.java

@SuppressWarnings("unused")
public static long getTotalBytes(File dir) {
    if (!dir.exists() && !dir.mkdirs()) {
        return 0;
    }//from w  w w . j a v  a2  s  . c  om
    StatFs dirStatFs = new StatFs(dir.getPath());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        return dirStatFs.getTotalBytes();
    } else {
        //noinspection deprecation
        return (long) dirStatFs.getBlockCount() * dirStatFs.getBlockSize();
    }
}

From source file:Main.java

@SuppressWarnings("WeakerAccess")
public static long getAvailableBytes(File dir) {
    if (!dir.exists() && !dir.mkdirs()) {
        return 0;
    }//from w  w  w .  ja  va 2 s.com
    StatFs dirStatFs = new StatFs(dir.getPath());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        return dirStatFs.getAvailableBytes();
    } else {
        //noinspection deprecation
        return (long) dirStatFs.getAvailableBlocks() * dirStatFs.getBlockSize();
    }
}