List of usage examples for java.io File mkdirs
public boolean mkdirs()
From source file:Main.java
public static boolean createFile(String path) throws ExecutionException, InterruptedException { if (TextUtils.isEmpty(path)) { return false; }//from w w w . ja v a 2 s. c o m final File file = new File(path); if (file.exists()) { return true; } return file.mkdirs(); }
From source file:Main.java
/** * Return the directory where the generated tlogs logging files are stored. * @return File to the tlogs directory/*from w ww .j a v a 2s .c om*/ */ private static File getTLogsDirectory(Context context) { File tlogDir = new File(context.getExternalFilesDir(null), DIRECTORY_TLOGS); if (!tlogDir.isDirectory()) { tlogDir.mkdirs(); } return tlogDir; }
From source file:Main.java
public static boolean makeFolder(String filePath) { String folderName = getFolderName(filePath); if (TextUtils.isEmpty(folderName)) { return false; }//from w ww . java2 s. co m File folder = new File(folderName); return (folder.exists() && folder.isDirectory()) ? true : folder.mkdirs(); }
From source file:Main.java
private static boolean checkFsWritable() { // Create a temporary file to see whether a volume is really writeable. // It's important not to put it in the root directory which may have a // limit on the number of files. String directoryName = Environment.getExternalStorageDirectory().toString() + "/DCIM"; File directory = new File(directoryName); if (!directory.isDirectory()) { if (!directory.mkdirs()) { return false; }//from www .j av a 2 s.c o m } File f = new File(directoryName, ".probe"); try { // Remove stale file if any if (f.exists()) { f.delete(); } if (!f.createNewFile()) { return false; } f.delete(); return true; } catch (IOException ex) { return false; } }
From source file:Main.java
public static void unzip(InputStream is, String dir) throws IOException { File dest = new File(dir); if (!dest.exists()) { dest.mkdirs(); }/* w w w.jav a2s . c o m*/ if (!dest.isDirectory()) throw new IOException("Invalid Unzip destination " + dest); if (null == is) { throw new IOException("InputStream is null"); } ZipInputStream zip = new ZipInputStream(is); ZipEntry ze; while ((ze = zip.getNextEntry()) != null) { final String path = dest.getAbsolutePath() + File.separator + ze.getName(); String zeName = ze.getName(); char cTail = zeName.charAt(zeName.length() - 1); if (cTail == File.separatorChar) { File file = new File(path); if (!file.exists()) { if (!file.mkdirs()) { throw new IOException("Unable to create folder " + file); } } continue; } FileOutputStream fout = new FileOutputStream(path); byte[] bytes = new byte[1024]; int c; while ((c = zip.read(bytes)) != -1) { fout.write(bytes, 0, c); } zip.closeEntry(); fout.close(); } }
From source file:mesclasses.util.EleveFileUtil.java
public static String copyFileForEleve(Eleve eleve, File file, String type) throws IOException { File eleveDir = getEleveDirWithType(eleve, type); eleveDir.mkdirs(); String fileName = FilenameUtils.getName(file.getPath()); File newFile = new File(eleveDir.getPath() + File.separator + fileName); if (newFile.exists()) { throw new IOException( "Le fichier " + fileName + " de type " + type + " existe dj pour " + eleve.getFirstName()); }//w ww . ja v a 2 s . c o m FileUtils.copyFile(file, newFile); return newFile.getPath(); }
From source file:mesclasses.util.EleveFileUtil.java
public static String moveFileForEleve(Eleve eleve, File file, String type) throws IOException { File eleveDir = getEleveDirWithType(eleve, type); eleveDir.mkdirs(); String fileName = FilenameUtils.getName(file.getPath()); File newFile = new File(eleveDir.getPath() + File.separator + fileName); if (newFile.exists()) { throw new IOException( "Le fichier " + fileName + " de type " + type + " existe dj pour " + eleve.getFirstName()); }/*from w ww . ja v a 2 s . com*/ FileUtils.moveFile(file, newFile); return newFile.getPath(); }
From source file:Main.java
public static void WriteToFile(String name, Bitmap bitmap, String path) throws IOException { String fString = name.replaceAll("/", "."); File dir = new File("/sdcard/OneBus/user/" + path); if (!dir.exists()) { dir.mkdirs(); }/*from w ww . j a v a2 s . co m*/ File f = new File("/sdcard/OneBus/user/" + path + "/" + fString + ".jpg"); f.createNewFile(); FileOutputStream fOut = null; try { fOut = new FileOutputStream(f); } catch (FileNotFoundException e) { e.printStackTrace(); } bitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut); try { fOut.flush(); } catch (IOException e) { e.printStackTrace(); } try { fOut.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static File getCacheDir(Context context) { Log.i("getCacheDir", "cache sdcard state: " + Environment.getExternalStorageState()); if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { File cacheDir = context.getExternalCacheDir(); if (cacheDir != null && (cacheDir.exists() || cacheDir.mkdirs())) { Log.i("getCacheDir", "cache dir: " + cacheDir.getAbsolutePath()); return cacheDir; }/*from ww w.ja va2 s . co m*/ } File cacheDir = context.getCacheDir(); Log.i("getCacheDir", "cache dir: " + cacheDir.getAbsolutePath()); return cacheDir; }
From source file:Main.java
/** * Saves a vcard string to an internal new vcf file. * @param vcard the string to save/*from ww w . j ava 2 s.c o m*/ * @param filename the filename of the vcf * @param context the context used to open streams. */ public static void saveToDisk(String vcard, String filename, Context context) { if (TextUtils.isEmpty(vcard) || TextUtils.isEmpty(filename) || context == null) { return; } String path = context.getFilesDir().getAbsolutePath() + File.separator + "peer_profiles"; File peerProfilesFile = new File(path); if (!peerProfilesFile.exists()) peerProfilesFile.mkdirs(); FileOutputStream outputStream; try { outputStream = new FileOutputStream(path + "/" + filename); outputStream.write(vcard.getBytes()); outputStream.close(); } catch (Exception e) { e.printStackTrace(); } }