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 OutputStream getOutputStream(File dir, String fileName) throws Exception {
    File outFile = new File(dir, fileName);
    // as this could be dir=.../maps fileName=preview/file.jpg
    // we need to make sure the preview dir exists, and if it does not, we must make it
    File parent = outFile.getParentFile();
    if (!parent.isDirectory() && !parent.mkdirs()) { // if it does not exist and i cant make it
        throw new RuntimeException("can not create dir " + parent);
    }/*from   w  ww .  j a va2 s  . c  om*/
    return new FileOutputStream(outFile);
}

From source file:Main.java

public static String checkAndMkdirs(String dir) {
    File file = new File(dir);
    if (file.exists() == false) {
        file.mkdirs();
    }/*from ww w  .  j  a  va 2s  .c om*/
    return dir;
}

From source file:Main.java

public static String getImageDir() {
    String fileDir = Environment.getExternalStorageDirectory() + "/fantasy/";

    File dirFile = new File(fileDir);
    if (!dirFile.exists()) {
        dirFile.mkdirs();
    }/* w  w  w .  j a  v  a2s .c  o  m*/

    return fileDir;
}

From source file:Main.java

public static boolean createDirIfNotExists(String path) {
    boolean ret = true;

    File file = new File(path);
    if (!file.exists()) {
        if (!file.mkdirs()) {
            Log.e("TravellerLog :: ", "Problem creating Image folder");
            ret = false;/* w  w w.j a v a2  s .c  o m*/
        }
    }
    return ret;

}

From source file:Main.java

public static void saveImage(Bitmap bmp) {
    String root = Environment.getExternalStorageDirectory().toString();
    File myDir = new File(root + "/abcxyz");
    myDir.mkdirs();
    Random generator = new Random();
    int n = 10000;
    n = generator.nextInt(n);/*from w  w  w  .j a v  a2 s . co m*/
    String name = "Image-" + n + ".jpg";
    File file = new File(myDir, name);
    if (file.exists())
        file.delete();

    try {
        FileOutputStream out = new FileOutputStream(file);
        bmp.compress(Bitmap.CompressFormat.JPEG, 100, out);
        out.flush();
        out.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static String getWaterPhotoPath() {
    File file = new File(path + "/WaterPhoto/");
    if (!file.exists()) {
        file.mkdirs();
    }/*from w  w w .jav  a2 s  .c om*/
    return path + "/WaterPhoto/";
}

From source file:Main.java

@SuppressLint("SdCardPath")
public static File getAlbumDir() {
    File dir = new File("/mnt/sdcard/bizchat/");
    if (!dir.exists()) {
        dir.mkdirs();
    }/* w  ww .j a  v  a  2s. co  m*/
    return dir;
}

From source file:Main.java

public static File getAppStorageDir(Context context) {
    File file = context.getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS);
    if (!file.mkdirs()) {
    }//from   w w w .ja v a2  s.  c  om
    return file;
}

From source file:Main.java

public static boolean createDir(String dirPath) {
    File file = new File(dirPath);
    if (!file.exists()) {
        file.mkdirs();
    }/*  ww w . j  ava 2s  .  co m*/
    return file.exists();
}

From source file:Main.java

private static String createDir(String dirPath) {
    try {/*from w  w w.ja va  2 s  .  com*/
        File dir = new File(dirPath);
        if (!dir.exists()) {
            dir.mkdirs();
        }
        return dir.getAbsolutePath();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return dirPath;
}