List of usage examples for java.io File mkdirs
public boolean mkdirs()
From source file:Main.java
private static File getExternalCacheDir() { File dataDir = new File(new File(Environment.getExternalStorageDirectory(), "Android"), "data"); File appCacheDir = new File(new File(dataDir, mContext.getPackageName()), "cache"); if (!appCacheDir.exists()) { if (!appCacheDir.mkdirs()) { return null; }/*from w w w. j a v a2 s . c o m*/ } return appCacheDir; }
From source file:com.eviware.soapui.Util.SoapUITools.java
public static Path ensureExists(Path path) { File file = path.toFile(); boolean ok = true; if (!file.exists()) { ok = file.mkdirs(); }/*from ww w . java 2 s. com*/ if (!ok) { throw new RuntimeException("Cannot create local storage at: " + file); } return path; }
From source file:com.clothcat.hpoolauto.JsonFileHelper.java
public static void writeToFile(JSONObject jo, String filename) { HLogger.log(Level.FINEST, "Attempting to write json to " + filename + "\n" + jo.toString()); // an array wrapper that we use to allow us to put a comment at the top // of the file to tell people not to edit JSONArray ja = new JSONArray(); ja.put("This file is part of the HyperPool Automation Tool (HAT)"); ja.put(" 2014 Stephen Stafford all rights wossnamed"); ja.put("DO NOT EDIT THIS FILE BY HAND. BAD THINGS WILL HAPPEN!!"); ja.put(jo);// w ww. jav a2 s. c o m HLogger.log(Level.FINEST, "After wrapping with comments array json looks " + "like: \n" + prettify(ja.toString())); String s = ja.toString(); s = prettify(s); File f = new File(Constants.JSON_FILEPATH); f.mkdirs(); f = new File(Constants.JSON_FILEPATH + filename); HLogger.log(Level.FINEST, "Attempting to write to file: " + filename); try (PrintWriter p = new PrintWriter(f)) { p.println(s); HLogger.log(Level.FINEST, "Wrote to file: " + filename); } catch (FileNotFoundException ex) { HLogger.log(Level.SEVERE, "Caught exception whilst trying to write to " + "file: " + filename, ex); Logger.getLogger(JsonFileHelper.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.exalttech.trex.stateful.utilities.FileManager.java
/** * Create directory if not exists/*from w w w . j a v a 2 s . c o m*/ * * @param directoryPath * @return */ public static String createDirectoryIfNotExists(String directoryPath) { File dir = new File(directoryPath); if (!dir.exists()) { dir.mkdirs(); } return directoryPath; }
From source file:com.jredrain.base.utils.CommandUtils.java
public static File createShellFile(String command, String shellFileName) { String dirPath = IOUtils.getTempFolderPath(); File dir = new File(dirPath); if (!dir.exists()) dir.mkdirs(); String tempShellFilePath = dirPath + File.separator + shellFileName + ".sh"; File shellFile = new File(tempShellFilePath); try {/* w ww . ja v a 2s .c om*/ if (!shellFile.exists()) { PrintWriter out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(tempShellFilePath))); out.write("#!/bin/bash\n" + command); out.flush(); out.close(); } } catch (Exception e) { e.printStackTrace(); } finally { return shellFile; } }
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("SU", "Unable to create external cache directory"); return null; }/* www .ja v a 2 s. c o m*/ try { new File(appCacheDir, ".nomedia").createNewFile(); } catch (IOException e) { Log.w("SU", "Can't create \".nomedia\" file in application external cache directory"); } } return appCacheDir; }
From source file:Main.java
public static void saveBackgroundImage(Context ctx, String filePath, Bitmap bitmap, int quality) throws IOException { if (bitmap != null) { File file = new File(filePath.substring(0, filePath.lastIndexOf(File.separator))); if (!file.exists()) { file.mkdirs(); }//from w w w . j a v a2s.c o m BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath)); bitmap.compress(CompressFormat.PNG, quality, bos); bos.flush(); bos.close(); if (ctx != null) { scanPhoto(ctx, filePath); } } }
From source file:Main.java
public static Uri createUri(String foldername) { String storageState = Environment.getExternalStorageState(); if (storageState.equals(Environment.MEDIA_MOUNTED)) { final File root = new File( Environment.getExternalStorageDirectory() + File.separator + foldername + File.separator); root.mkdirs(); final String fname = getUniqueImageFilename(foldername); final File sdImageMainDirectory = new File(root, fname); return Uri.fromFile(sdImageMainDirectory); }/*from w w w. j a v a2 s. c o m*/ return null; }
From source file:net.pocketpixels.hubmanager.DBmanager.java
/** *Loads the object of class type out of JSON from the given file * @param type The class of the object to be loaded * @param loc the location of the file to load the data from * @return returns the loaded object as an Object *///from ww w .j a v a 2 s . c o m public static Object loadObj(Class type, File loc) { if (!loc.exists()) { loc.mkdirs(); return false; } Object obj; try { obj = JSonParser.readValue(loc, type); } catch (IOException ex) { ex.printStackTrace(); return false; } return obj; }
From source file:com.gs.obevo.util.LogUtil.java
private static FileLogger configureLogging(File workDir, String fileName) { if (!workDir.isDirectory()) { workDir.mkdirs(); }/*from w w w. ja va2 s . c om*/ return new LogbackFileLogger(workDir + "/" + fileName); }