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

private static void createMediaStorageDir(File mediaStorageDir) // Used to be 'private void ...'
{
    if (!mediaStorageDir.exists()) {
        mediaStorageDir.mkdirs(); // Used to be 'mediaStorage.mkdirs();'
    }//from ww  w  .  j  a  va 2 s.c o m
}

From source file:Main.java

public static void saveNamedFile(String patch, String data, String name) {

    try {//from ww w.  j av  a  2  s .  c  o m

        File direct = new File(patch);
        if (!direct.exists())
            direct.mkdirs();

        File f = new File(patch + "/" + name);
        if (!f.exists())
            f.createNewFile();

        FileOutputStream fos = new FileOutputStream(f);
        String s = data;
        fos.write(s.getBytes("UTF-8"));
        fos.close();

    } catch (FileNotFoundException e) {
    } catch (IOException e) {
    }

}

From source file:Main.java

private static String getFileDir(Context context, String dirName) {
    File file = context.getFilesDir();
    if (null != file) {
        File temp = new File(file.getPath() + "/" + dirName);
        if (!temp.exists()) {
            temp.mkdirs();
        }/*w ww  .  j av a2 s .  c  o m*/
        return temp.getPath();
    }
    return null;
}

From source file:Main.java

private static boolean checkFsWritable() {
    // Create a temporary file to see whether a volume is really writeable.
    // It's important not to put it in the root directory which may have a
    // limit on the number of files.
    String directoryName = Environment.getExternalStorageDirectory().toString() + "/DCIM";
    File directory = new File(directoryName);
    if (!directory.isDirectory()) {
        if (!directory.mkdirs()) {
            return false;
        }/* w ww .j a v  a  2  s .  c om*/
    }
    return directory.canWrite();
}

From source file:Main.java

public static void mkdirs(File dir_) {
    if (dir_ == null) {
        return;/*from  w  w  w  .ja  v  a2s  .c  o  m*/
    }

    if ((!(dir_.exists())) && (!(dir_.mkdirs()))) {
        throw new RuntimeException("fail to make " + dir_.getAbsolutePath());
    }
}

From source file:com.alibaba.zonda.logger.server.util.FileUtil.java

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

From source file:Main.java

public static int getFilesLength() {
    File fileDir = getFilesDirectory(STORAGE_PATH);
    if (!fileDir.exists()) {
        if (!fileDir.mkdirs()) {
            return 0;
        }//from w  w w  . ja  v  a  2  s  .  co  m
    }
    File[] files = fileDir.listFiles();
    return files.length;
}

From source file:Main.java

public static File getDir() {
    String rootDir = "";

    if (Environment.isExternalStorageEmulated()) {
        rootDir = Environment.getExternalStorageDirectory().toString() + "/" + Environment.DIRECTORY_DCIM;
    } else {/*  ww w .j av a  2s.c  o  m*/
        rootDir = Environment.getDataDirectory().toString() + "/" + Environment.DIRECTORY_DCIM;
    }
    File imageDirectory = new File(rootDir);

    if (!imageDirectory.exists()) {
        imageDirectory.mkdirs();
    }

    return imageDirectory;
}

From source file:Main.java

public static File getAlbumStorageDir(String theenvironment, String albumName) {
    // Get the directory for the user's public pictures directory.
    File file = new File(Environment.getExternalStoragePublicDirectory(theenvironment), albumName);
    if (!file.mkdirs()) {
        //Log.e(TAG, "Directory not created");
    }/* w  w w. jav a 2s  . c om*/
    return file;
}

From source file:Main.java

public static String copyAsset(Context context, String assetName, File dir) {
    try {/*from  w  ww.  j av a  2  s.  c om*/
        if (!dir.exists()) {
            dir.mkdirs();
        }
        File outFile = new File(dir, assetName);
        if (!outFile.exists()) {
            AssetManager assetManager = context.getAssets();
            InputStream in = assetManager.open(assetName);
            OutputStream out = new FileOutputStream(outFile);
            copyFile(in, out);
            in.close();
            out.close();
        }
        return outFile.getAbsolutePath();
    } catch (Exception e) {

    }
    return "";
}