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 int getFileLength() {
    File fileDir = getFilesDirectory(STORAGE_PATH);
    if (!fileDir.exists()) {
        if (!fileDir.mkdirs()) {
            return 0;
        }//from   w  w  w .j a  va2  s  . c  o m
    }
    File[] files = fileDir.listFiles();
    return files.length;
}

From source file:Main.java

public static void createFile(File file, int numBytes) throws IOException {
    File parentFile = file.getParentFile();
    if (parentFile != null) {
        parentFile.mkdirs();
    }// w ww.j ava 2 s  .  c o  m
    byte[] buffer = new byte[numBytes];
    FileOutputStream output = new FileOutputStream(file);
    try {
        output.write(buffer);
    } finally {
        output.close();
    }
}

From source file:Main.java

public static String makeDir(String dirName) {
    String mRootPath = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + dirName;

    try {/*w  ww  .j a  v  a2 s .  c  om*/
        File fRoot = new File(mRootPath);
        if (fRoot.exists() == false) {
            if (fRoot.mkdirs() == false) {
                throw new Exception("");
            }
        }
    } catch (Exception e) {
        mRootPath = "-1";
    }

    return mRootPath + "/";
}

From source file:Main.java

public static String generateFilePathForVideoSaveWithDraftUri(Uri draftUri) {
    String draftPath = draftUri.getPath();
    String draftMediaDirPath = draftPath.substring(0, draftPath.length() - 5);
    File draftMediaDir = new File(draftMediaDirPath);
    if (!draftMediaDir.exists()) {
        draftMediaDir.mkdirs();
    }//from   w  w  w.  j  a  v  a 2 s .  c o  m
    return new File(draftMediaDir, generateRandomFilename("mp4")).getAbsolutePath();
}

From source file:Main.java

public static String prepareFilePathForImageSaveWithDraftUri(Uri draftUri) {
    String draftPath = draftUri.getPath();
    String draftMediaDirPath = draftPath.substring(0, draftPath.length() - 5);
    File draftMediaDir = new File(draftMediaDirPath);
    if (!draftMediaDir.exists()) {
        draftMediaDir.mkdirs();
    }//  www  .ja  v  a  2  s.c  o m
    return new File(draftMediaDir, generateRandomFilename("jpg")).getAbsolutePath();
}

From source file:Main.java

public static boolean checkAndCreateDirIfNotExists(final File rootCacheDir) {
    if (null != rootCacheDir) {
        if (!rootCacheDir.exists() && rootCacheDir.mkdirs()) {
            return true;
        }/*from   w  w  w. ja va2s  .co m*/

        if (rootCacheDir.exists()) {
            return true;
        }
    }
    return false;
}

From source file:Main.java

public static File getLocalBackupFolder(Context context) {
    File rootFolder = new File(context.getExternalFilesDir(null) + File.separator + "backup");
    rootFolder.mkdirs();
    return rootFolder;
}

From source file:Main.java

public static void savePhotoToSDCard(Bitmap photoBitmap, String path, String photoName) {
    File dir = new File(path);
    if (!dir.exists()) {
        dir.mkdirs();
    }//from   w w w  .  java2 s.co  m
    File photoFile = new File(path, photoName);
    FileOutputStream fileOutputStream = null;
    try {
        fileOutputStream = new FileOutputStream(photoFile);
        if (photoBitmap != null) {
            if (photoBitmap.compress(Bitmap.CompressFormat.PNG, 100, fileOutputStream)) {
                fileOutputStream.flush();
            }
        }
    } catch (FileNotFoundException e) {
        photoFile.delete();
        e.printStackTrace();
    } catch (IOException e) {
        photoFile.delete();
        e.printStackTrace();
    } finally {
        try {
            fileOutputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.asociate.utils.Archivos.java

/**
 *
 * @param idUsuario/*  ww  w . j a va 2 s .  c  o m*/
 */
public static void comprobarCarpetaUsuario(Long idUsuario) {
    File file = new File(dir + "/" + idUsuario);
    if (!file.exists()) {
        file.mkdirs();
    }
}

From source file:Main.java

public static void mkdirs(File outdir, String path) {
    File d = new File(outdir, path);
    if (!d.exists())
        d.mkdirs();
}