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 File creatSDDir(String dir) {
    File dirFile = new File(SDCardRoot + dir + File.separator);
    dirFile.mkdirs();
    return dirFile;
}

From source file:Main.java

public static Boolean createFile(String path) {
    File file = new File(path);
    File parantFile = file.getParentFile();
    if (null != parantFile && !parantFile.exists() && !parantFile.mkdirs()) {
        return false;
    }/*  w  ww . ja  v a2  s .c  o m*/

    try {
        file.createNewFile();
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }
    return true;
}

From source file:Main.java

public static File createImageInExternalStoragePublicDirectory(String filename) {

    File path = Environment.getExternalStoragePublicDirectory("uDrove");
    File file = new File(path, filename + ".jpg");
    path.mkdirs();

    return file;//from   ww  w .  ja v  a 2  s .co m

}

From source file:Main.java

public static File getLocalRoot() {
    File tmp = Environment.getExternalStorageDirectory();
    tmp = new File(tmp, "webapp");
    if (!tmp.exists()) {
        tmp.mkdirs();
    }// w w  w  . j  av a 2  s  .c  o m
    return tmp;
}

From source file:Main.java

public static OutputStream openFileStream(String directory, String filePath) {
    if (TextUtils.isEmpty(directory) || TextUtils.isEmpty(filePath)) {
        return null;
    }/*w  w w  .  j  av  a  2  s.  c  om*/

    File directoryFile = new File(directory);
    if (!directoryFile.exists()) {
        directoryFile.mkdirs();
    }

    File file = new File(directory + File.separator + filePath);
    try {
        if (!file.exists()) {
            file.createNewFile();
        }
        return new FileOutputStream(file, true);
    } catch (Exception ex) {
        ex.printStackTrace();
        return null;
    }
}

From source file:Main.java

public static void touch(File file) throws IOException {
    if (!file.exists()) {
        File parent = file.getParentFile();
        if (parent != null)
            if (!parent.exists())
                if (!parent.mkdirs())
                    throw new IOException("Cannot create parent directories for file: " + file);
        file.createNewFile();//from   ww  w. ja  v  a  2 s .  c om
    }
}

From source file:Main.java

public static boolean storePropertyInstance(String filePath, String fileName, Properties p, String comment) {
    try {/*from  www  .  ja  v  a2  s  .com*/
        File d = new File(filePath);
        if (!d.exists()) {
            d.mkdirs();
        }
        File f = new File(d, fileName);
        if (!f.exists()) {
            f.createNewFile();
        }
        OutputStream os = new FileOutputStream(f);
        p.store(os, comment);
        os.close();
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

From source file:Main.java

public static boolean saveBitmapToSDCard(Bitmap bitmap, String filePath, String fileName) {
    boolean flag = false;
    if (null != bitmap) {
        try {/*from  ww  w .ja  v  a  2 s  .c om*/
            fileName = fileName + ".jpg";
            File file = new File(filePath);
            if (!file.exists()) {
                file.mkdirs();
            }
            File f = new File(filePath + fileName);
            if (f.exists()) {
                f.delete();
            }
            BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(f));
            bitmap.compress(CompressFormat.JPEG, 100, outputStream);
            outputStream.flush();
            outputStream.close();
            flag = true;
        } catch (FileNotFoundException e) {
            flag = false;
        } catch (IOException e) {
            flag = false;
        }
    }
    return flag;

}

From source file:actors.ConfigUtil.java

/**
 * Generate the config file in the 'wherehows.app_folder' folder
 * The file name is {whEtlExecId}.config
 *
 * @param whEtlExecId/*from  w  w w.  j a  v  a  2  s .c om*/
 * @param props
 * @return void
 */
static void generateProperties(long whEtlExecId, Properties props, String outDir) throws IOException {
    File dir = new File(outDir);
    if (!dir.exists()) {
        dir.mkdirs();
    }

    File configFile = new File(dir, whEtlExecId + ".properties");
    FileWriter writer = new FileWriter(configFile);
    props.store(writer, "exec id : " + whEtlExecId + " job configurations");
    writer.close();
}

From source file:Main.java

private static void saveFileForLocal(String requestPath, String result) {
    // TODO Auto-generated method stub
    File file = new File(requestPath);
    if (!file.exists()) {
        try {/*  ww w  .j a v  a2 s . c o m*/
            File parentFile = file.getParentFile();
            if (!parentFile.exists()) {
                parentFile.mkdirs();
            }
            file.createNewFile();
            FileOutputStream fout = new FileOutputStream(file);
            byte[] buffer = result.getBytes();
            fout.write(buffer);
            fout.close();
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}