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

public static File getVideoDirectory() {
    File videoDirectory = new File(getMultimediaDirectory(), "video");
    if (!videoDirectory.exists()) {
        videoDirectory.mkdir();
    }// w ww  .jav a  2 s . co  m
    return videoDirectory;
}

From source file:Main.java

public static File getImageDirectory() {
    File imageDirectory = new File(getMultimediaDirectory(), "image");
    if (!imageDirectory.exists()) {
        imageDirectory.mkdir();
    }/*  w  w w  . j  ava2 s. c om*/
    return imageDirectory;
}

From source file:Main.java

/**
 * @return Directory for file storage while downloading
 */// w w  w  .  j  a  va 2s .  c o m
public static File getPath() {

    File dir = new File(Environment.getExternalStorageDirectory() + "/Videos");

    if (!dir.exists()) {
        dir.mkdir();
    }

    return dir;
}

From source file:Main.java

public static void createSDFolder() {
    File direct = new File(Environment.getExternalStorageDirectory() + "/FranqInterface");
    if (!direct.exists()) {
        direct.mkdir();
    }/*from  w w w.jav a 2  s  . co  m*/
}

From source file:eu.riscoss.RemoteRiskAnalyserMain.java

static void loadJSmile() throws Exception {
    File dir = new File(FileUtils.getTempDirectory(), "jnativelibs-" + RandomStringUtils.randomAlphabetic(30));
    if (!dir.mkdir()) {
        throw new Exception("failed to make dir");
    }//from w ww  .j  a  v  a 2 s .  co m
    File jsmile = new File(dir, "libjsmile.so");
    URL jsmURL = Thread.currentThread().getContextClassLoader().getResource("libjsmile.so");
    FileUtils.copyURLToFile(jsmURL, jsmile);
    System.setProperty("java.library.path",
            System.getProperty("java.library.path") + ":" + dir.getAbsolutePath());

    // flush the library paths
    Field sysPathsField = ClassLoader.class.getDeclaredField("sys_paths");
    sysPathsField.setAccessible(true);
    sysPathsField.set(null, null);

    // Check that it works...
    System.loadLibrary("jsmile");

    dir.deleteOnExit();
    jsmile.deleteOnExit();
}

From source file:Main.java

public static void savePic2SD(Bitmap bitmap, String path, String folder) {

    boolean sdCardExist = Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
    if (sdCardExist) {
        File fileDir = new File(folder);
        if (!fileDir.exists()) {
            fileDir.mkdir();
        }/*from  www  . jav a 2 s  .co m*/
    }

    File file = new File(path);
    if (file.exists()) {
        file.delete();
    }
    try {
        FileOutputStream out = new FileOutputStream(file);

        if (bitmap.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

/**
 * Helper method to calculate the proper size limit of a cache instance.
 *//*from  w  w  w .  j ava2s.c  o m*/
public static long getCacheSizeInBytes(File dir, float cacheSizePercent, long maxSizeInBytes) {
    if (dir == null || (!dir.exists() && !dir.mkdir())) {
        return 0;
    }
    try {
        StatFs stat = new StatFs(dir.getPath());
        long totalBytes = stat.getBlockCountLong() * stat.getBlockSizeLong();
        long freeBytes = stat.getAvailableBlocksLong() * stat.getBlockSizeLong();
        long desiredBytes = Math.min((long) (totalBytes * cacheSizePercent), maxSizeInBytes);
        // If free space is less than desired, use half of the free disk space instead.
        desiredBytes = (desiredBytes > freeBytes) ? freeBytes / 2 : desiredBytes;
        return desiredBytes;
    } catch (IllegalArgumentException e) {
        return 0;
    }
}

From source file:eu.sisob.uma.restserver.FileSystemManager.java

/**
 *
 * @param path//from   w ww  .j a v a2 s  .c  om
 * @return
 * @throws IOException
 */
public static File createFileAndIfExistsDelete(String path) throws IOException {

    File dir = new File(path);
    if (!dir.exists())
        dir.mkdir();
    else {
        FileUtils.deleteDirectory(dir);
        dir.mkdir();
    }

    return dir;
}

From source file:Main.java

public static void copyFileOrDir(Context ctx, String path) throws IOException {
    String assets[] = ctx.getApplicationContext().getAssets().list(path);
    if (assets.length == 0) {
        copyFile(ctx, path);//from  w  ww  . j  a  va 2 s .c  o m
    } else {
        StringBuilder fullPath = new StringBuilder();
        fullPath.append(DATA_DIR).append(ctx.getPackageName()).append("/").append(path);
        File dir = new File(fullPath.toString());
        if (!dir.exists())
            dir.mkdir();
        for (int i = 0; i < assets.length; ++i) {
            copyFileOrDir(ctx, path + "/" + assets[i]);
        }
    }
}

From source file:Main.java

private static String getInternalStoragePathByContext(String path, Context context) {
    File dirPath = context.getDir(path, Context.MODE_PRIVATE);
    if (dirPath.exists()) {
        dirPath.mkdir();
    }/*www  .  ja  va  2 s.  c om*/
    return dirPath.getAbsolutePath();
}