List of usage examples for java.io File mkdirs
public boolean mkdirs()
From source file:Main.java
public static String assetToSd(Context ctx, String inFileName, String outFileName) { try {//from w w w.jav a 2 s . c om InputStream is = ctx.getAssets().open(inFileName); if (is == null) { return null; } if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) { String sd = Environment.getExternalStorageDirectory().getAbsolutePath(); String path = sd + "/uexTencent/"; File filePath = new File(path); if (!filePath.exists()) { filePath.mkdirs(); } String fileName = path + outFileName; FileOutputStream fos = new FileOutputStream(fileName); byte[] buf = new byte[1024]; int len = 0; int total = 0; while ((len = is.read(buf)) != -1) { fos.write(buf, 0, len); total++; } is.close(); fos.close(); fileSize = total; return fileName; } } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static File createTemporaryFile(String part, String ext) throws Exception { File tempDir = Environment.getExternalStorageDirectory(); tempDir = new File(tempDir.getAbsolutePath() + "/.temp/"); if (!tempDir.exists()) { tempDir.mkdirs(); }//w ww .j ava 2 s. c om return File.createTempFile(part, ext, tempDir); }
From source file:Main.java
public static void setupLogcatLogs(ApplicationInfo appInfo) { if (0 != (appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE)) { File f = new File(Environment.getExternalStorageDirectory(), "rockscout_logs"); if (!f.exists()) { f.mkdirs(); }/* w w w . java2s.c o m*/ String filePath = Environment.getExternalStorageDirectory() + String.format("/rockscout_logs/logcat_%s.txt", Calendar.getInstance().getTime().toString()); try { Runtime.getRuntime().exec(new String[] { "logcat", "-v", "time", "-f", filePath }); } catch (IOException e) { } } }
From source file:Main.java
public static void unCompress(String zipPath, String toPath) throws IOException { File zipfile = new File(zipPath); if (!zipfile.exists()) return;/*from w w w .ja v a 2s . c om*/ if (!toPath.endsWith("/")) toPath += "/"; File destFile = new File(toPath); if (!destFile.exists()) destFile.mkdirs(); ZipInputStream zis = new ZipInputStream(new FileInputStream(zipfile)); ZipEntry entry = null; try { while ((entry = zis.getNextEntry()) != null) { if (entry.isDirectory()) { File file = new File(toPath + entry.getName() + "/"); file.mkdirs(); } else { File file = new File(toPath + entry.getName()); if (!file.getParentFile().exists()) file.getParentFile().mkdirs(); FileOutputStream fos = null; try { fos = new FileOutputStream(file); byte buf[] = new byte[1024]; int len = -1; while ((len = zis.read(buf, 0, 1024)) != -1) { fos.write(buf, 0, len); } } finally { if (fos != null) { try { fos.close(); } catch (Exception e) { } } } } } } finally { zis.close(); } }
From source file:Main.java
private static File getExternalCacheDir(Context context) { File dataDir = new File(new File(Environment.getExternalStorageDirectory(), "Android"), "data"); File appCacheDir = new File(new File(dataDir, context.getPackageName()), "cache"); if (!appCacheDir.exists()) { if (!appCacheDir.mkdirs()) { Log.w(TAG, "Unable to create external cache directory"); return null; }/*from w w w. j ava2 s .co m*/ try { new File(appCacheDir, ".nomedia").createNewFile(); } catch (IOException e) { Log.i(TAG, "Can't create \".nomedia\" file in application external cache directory"); } } return appCacheDir; }
From source file:com.ikanow.infinit.e.harvest.enrichment.legacy.HttpClientPost.java
private static void verifyArgs(String[] args) { if (args.length == 0) { usageError("no params supplied"); } else if (args.length < 2) { usageError("2 params are required"); } else {//from w w w. ja v a 2 s . c om if (!new File(args[0]).exists()) usageError("file " + args[0] + " doesn't exist"); File outdir = new File(args[1]); if (!outdir.exists() && !outdir.mkdirs()) usageError("couldn't create output dir"); } }
From source file:edu.harvard.iq.dataverse.batch.util.LoggingUtil.java
public static void saveJsonLog(String jobJson, String logDir, String jobId) { try {/*from w w w . j ava2 s. c o m*/ checkCreateLogDirectory(logDir); File dir = new File(logDir); if (!dir.exists() && !dir.mkdirs()) { logger.log(Level.SEVERE, "Couldn't create directory: " + dir.getAbsolutePath()); } File reportJson = new File(dir.getAbsolutePath() + "/job-" + jobId + ".json"); FileUtils.writeStringToFile(reportJson, jobJson); } catch (Exception e) { logger.log(Level.SEVERE, "Error saving json report: " + e.getMessage()); } }
From source file:Main.java
/** * Base64 to File/*from ww w . j a va 2s . c o m*/ * @param base64Str * @param filePath * @param fileName * @throws FileNotFoundException * @throws IOException */ public static void saveBase64StringToFile(String base64Str, String filePath, String fileName) throws FileNotFoundException, IOException { BufferedOutputStream bos = null; FileOutputStream fos = null; File file = null; try { File dir = new File(filePath); if (!dir.exists() && dir.isDirectory()) { dir.mkdirs(); } file = new File(filePath, fileName); fos = new FileOutputStream(file); bos = new BufferedOutputStream(fos); byte[] bfile = Base64.decode(base64Str, Base64.DEFAULT); bos.write(bfile); } catch (FileNotFoundException e) { throw e; } catch (IOException e) { throw e; } finally { if (bos != null) { try { bos.close(); } catch (IOException e1) { e1.printStackTrace(); } } if (fos != null) { try { fos.close(); } catch (IOException e1) { e1.printStackTrace(); } } } }
From source file:muffinc.yafdivj.helper.FeretHandler.java
public static void moveToHumans() { File file = new File(NEW_FOLDER); for (File file1 : file.listFiles()) { if (file1.isDirectory()) { for (File file2 : file1.listFiles(((FileFilter) new RegexFileFilter("\\w{10}d.*")))) { try { String newFolder = "/Users/Meth/Documents/FROG/src/test/resources/Humans/" + "H_" + file2.getName().substring(1, 5) + "/"; File file3 = new File(newFolder); if (!file3.exists()) { file3.mkdirs(); }// w ww. ja v a2 s. c om Files.copy(file2.toPath(), new File(newFolder + file2.getName()).toPath()); } catch (IOException e) { e.printStackTrace(); } } } } }
From source file:Main.java
private static void mkdirs(File outdir, String path) { File d = new File(outdir, path); if (!d.exists()) { //noinspection ResultOfMethodCallIgnored d.mkdirs(); }// www . j ava 2 s . c o m }