List of usage examples for java.io File mkdirs
public boolean mkdirs()
From source file:Main.java
public static boolean saveFile(Bitmap bm, String fileDir, String fileName) { try {//w w w .j a v a 2 s . c om File dirFile = new File(fileDir); if (!dirFile.exists()) { dirFile.mkdirs(); } File myCaptureFile = new File(fileDir, fileName + ".jpg"); if (myCaptureFile.exists()) { myCaptureFile = new File(fileDir, fileName + System.currentTimeMillis() + ".jpg"); } BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(myCaptureFile)); bm.compress(CompressFormat.JPEG, 100, bos); bos.flush(); bos.close(); return true; } catch (Exception e) { e.printStackTrace(); } return false; }
From source file:Main.java
public static int copyFile(String fileDir, String fileName, byte[] buffer) { if (buffer == null) { return -2; }/* w w w.ja v a 2 s. c om*/ try { File file = new File(fileDir); if (!file.exists()) { file.mkdirs(); } File resultFile = new File(file, fileName); if (!resultFile.exists()) { resultFile.createNewFile(); } BufferedOutputStream bufferedOutputStream = new BufferedOutputStream( new FileOutputStream(resultFile, true)); bufferedOutputStream.write(buffer); bufferedOutputStream.flush(); bufferedOutputStream.close(); return 0; } catch (Exception e) { } return -1; }
From source file:Main.java
private static File getKeysDirectory(Context context, String name) { File directory = new File(context.getFilesDir(), name); if (!directory.exists()) directory.mkdirs(); return directory; }
From source file:Main.java
public static File saveBitmap(Bitmap bitmap, String path, String picName) { File dir = new File(path); if (dir != null && !dir.exists()) { dir.mkdirs(); }/*from w w w . j a v a2 s . c om*/ File file = new File(dir, picName); try { FileOutputStream fos = new FileOutputStream(file); bitmap.compress(CompressFormat.PNG, 100, fos); fos.close(); } catch (IOException e) { e.printStackTrace(); return null; } return file; }
From source file:Main.java
public static void copyFile(File srcFile, File desFile) throws FileNotFoundException, IOException { try {/*from w ww . ja v a 2 s.c o m*/ File parent = desFile.getParentFile(); if (!parent.exists()) { parent.mkdirs(); } } catch (Exception e) { } // InputStream input = new FileInputStream(srcFile); OutputStream output = new FileOutputStream(desFile); copyFileStream(input, output); }
From source file:Main.java
public static File getFile(String path) throws IOException { String dirPath = path.substring(0, path.lastIndexOf(File.separator)); File dirFile = new File(dirPath); File file = new File(path); if (!dirFile.exists()) dirFile.mkdirs(); if (!file.exists()) file.createNewFile();//from w w w . ja v a 2 s. c o m return file; }
From source file:Main.java
public static File getSkinDir(Context context) { File skinDir = new File(getCacheDir(context), "skin"); if (skinDir.exists()) { skinDir.mkdirs(); }//from ww w. j a v a 2s .co m return skinDir; }
From source file:Main.java
public static void makeDirsByPath(String path) { File dirFile = null; dirFile = new File(path); if (!dirFile.exists()) { dirFile.mkdirs(); }/*from ww w . j a v a 2s .co m*/ dirFile = null; }
From source file:Main.java
public static void rename(File from, File to, boolean delete) { if (!from.exists()) { return;//from w ww . ja v a 2s. com } boolean isRename = false; if (to.exists()) { if (delete) { to.delete(); isRename = true; } else { isRename = false; } } else { isRename = true; } if (isRename) { File parent = to.getParentFile(); if (!parent.exists()) { parent.mkdirs(); } from.renameTo(to); } }
From source file:Main.java
public static String getLyricDir() { File file = Environment.getExternalStorageDirectory(); if (file == null) { return null; }//from ww w .j a v a 2s. c o m File f = new File(file.getAbsolutePath() + LYRICS_DIR); if (!f.exists()) { f.mkdirs(); } return f.getAbsolutePath(); }