Example usage for java.io File mkdir

List of usage examples for java.io File mkdir

Introduction

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

Prototype

public boolean mkdir() 

Source Link

Document

Creates the directory named by this abstract pathname.

Usage

From source file:Main.java

/**
 * utility method to create a folder//from w  ww . j a  va2 s.  c o m
 *
 * @param path full path to create
 * @return {@link File} object of the folder just created
 * @throws IOException
 */
private static File createFolder(String path) throws IOException {
    File file = new File(path);
    if (!file.exists()) {
        if (!file.mkdir()) {
            throw new IOException("couldn't create folder '" + path + "'");
        }
    }
    return file;
}

From source file:Main.java

public static boolean createDirectory(String directoryName) {
    boolean status;
    if (!directoryName.equals("")) {
        File path = Environment.getExternalStorageDirectory();
        File newPath = new File(path.toString() + directoryName);
        status = newPath.mkdir();
        status = true;/* www  .  java2 s.com*/
    } else
        status = false;
    return status;
}

From source file:Main.java

public static String getPicStorePath(Context ctx) {
    File file = ctx.getExternalFilesDir(null);
    if (!file.exists()) {
        file.mkdir();
    }/*  w  ww. j ava2s.  co  m*/
    File imageStoreFile = new File(file.getAbsolutePath() + "/mq");
    if (!imageStoreFile.exists()) {
        imageStoreFile.mkdir();
    }
    return imageStoreFile.getAbsolutePath();
}

From source file:Main.java

public static String getExtraPath(String folder) {
    String storagePath = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + folder;
    File file = new File(storagePath);
    if (!file.exists()) {
        file.mkdir();
    }//from www .j a va2 s . co  m
    return storagePath;
}

From source file:Main.java

private static long getDirSize(File dir) {

    long size = 0;
    if (!dir.exists()) {
        dir.mkdir();
    }//w  ww.j  a  v  a  2  s  . c  om
    File[] files = dir.listFiles();

    for (File file : files) {
        if (file.isFile()) {
            size += file.length();
        }
    }

    return size;
}

From source file:Main.java

public static String createNewPrivateFolder(String folderName) {
    String folderPathString = getSDPath() + mPrivatePath + folderName;
    if (folderPathString.charAt(folderPathString.length() - 1) != '/') {
        folderPathString += '/';
    }/*from ww  w.j  a v  a 2 s  . c  om*/
    File path = new File(folderPathString);
    if (!path.exists()) {
        path.mkdir();
    }
    return folderPathString;
}

From source file:Main.java

public static File folderName() {
    File file = new File(folderName);
    if (!file.exists())
        file.mkdir();
    return file;/*  w  ww  .jav  a 2s .c  o m*/
}

From source file:Main.java

public static void dirCreate(File dir) {

    if (!dir.exists()) {
        dirCreate(dir.getParentFile());/*from   w w  w.  j  a v a2 s.  c o m*/
        dir.mkdir();
    }
}

From source file:Main.java

public static boolean hasSDCard(Context context) {
    if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) {
        String dir = Environment.getExternalStorageDirectory() + FILE_DIR;
        File f = new File(dir);
        if (!f.exists()) {
            f.mkdir();
        } else {//from w  w  w . j a v a  2  s.  c o m
            try {
                for (File t : f.listFiles()) {
                    t.delete();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return true;
    }
    return false;
}

From source file:Main.java

public static void saveFile(Bitmap bm, String path, String fileName) throws IOException {
    String uri = path;/*from w  w w .ja va  2 s  .  co m*/
    if (!uri.endsWith("/")) {
        uri = uri + "/";
    }
    uri = uri + fileName;
    File dirFile = new File(path);
    if (!dirFile.exists()) {
        dirFile.mkdir();
    }
    File myCaptureFile = new File(uri);
    BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(myCaptureFile));
    bm.compress(Bitmap.CompressFormat.JPEG, 80, bos);
    bos.flush();
    bos.close();
    // SharedPreferences sp=
}