List of usage examples for java.io File mkdirs
public boolean mkdirs()
From source file:com.liferay.maven.plugins.util.FileUtil.java
public static void mkdirs(String pathName) { File file = new File(pathName); file.mkdirs(); }
From source file:Main.java
public static void put(String s, String name) { try {// ww w. j a v a 2 s .co m File saveFile = new File(Environment.getExternalStorageDirectory() + "/hhtlog/" + name + ".txt"); if (!saveFile.exists()) { File dir = new File(saveFile.getParent()); dir.mkdirs(); saveFile.createNewFile(); } FileOutputStream outStream = new FileOutputStream(saveFile); outStream.write(s.getBytes()); outStream.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static boolean createFile(String filename) { final File file = new File(filename); final File pf = file.getParentFile(); if (!pf.exists()) { pf.mkdirs(); }// w w w . j av a 2 s. co m if (!file.exists()) { try { file.createNewFile(); } catch (IOException e) { e.printStackTrace(); return false; } } return true; }
From source file:Main.java
/** * Return a file with the given filename creating the necessary directories * if not present.//from w ww .j a va 2 s . c o m * * @param filename * The file * @return The created File instance */ public static File createFile(File destDir, String filename) { File file = new File(destDir, filename); File parent = file.getParentFile(); if (parent != null) parent.mkdirs(); return file; }
From source file:ca.travelagency.utils.UploadUtils.java
public static File getUploadFolder(String companyFolder) { Validate.notNull(companyFolder);// w w w . j av a 2 s. c o m File folder = new File(MAIN_FOLDER + companyFolder, UPLOAD_FOLDER); folder.mkdirs(); return folder; }
From source file:Main.java
public static File getPhotoCacheDir(Context context, File file) { File cacheDir = context.getCacheDir(); if (cacheDir != null) { File mCacheDir = new File(cacheDir, DEFAULT_DISK_CACHE_DIR); if (!mCacheDir.mkdirs() && (!mCacheDir.exists() || !mCacheDir.isDirectory())) { return file; } else {/*from w w w.j a v a 2 s . co m*/ return new File(mCacheDir, file.getName()); } } if (Log.isLoggable(TAG, Log.ERROR)) { Log.e(TAG, "default disk cache dir is null"); } return file; }
From source file:Main.java
public static String getInstanceFolder(String appName, String tableId, String instanceId) { String path;//from w ww . j a v a 2 s . c o m if (instanceId == null || instanceId.length() == 0) { throw new IllegalArgumentException("getInstanceFolder: instanceId is null or the empty string!"); } else { String instanceFolder = instanceId.replaceAll("(\\p{P}|\\p{Z})", "_"); path = getTablesFolder(appName, tableId) + File.separator + INSTANCES_FOLDER_NAME + File.separator + instanceFolder; } File f = new File(path); f.mkdirs(); return f.getAbsolutePath(); }
From source file:Main.java
public static boolean createParentDir(File file) { boolean isMkdirs = true; if (!file.exists()) { File dir = file.getParentFile(); if (!dir.exists()) { isMkdirs = dir.mkdirs(); }/*from w w w . j a va2s.co m*/ } return isMkdirs; }
From source file:Main.java
private static boolean makeDirectory(String path) { if (path == null) { return false; }/*from w w w.j ava2 s .c o m*/ File directory = new File(path); return directory.exists() && directory.isDirectory() || directory.mkdirs(); }
From source file:Main.java
private static final void copyInputStream(InputStream in, String fileName) throws FileNotFoundException { File file = new File(fileName); File parentFile = file.getParentFile(); parentFile.mkdirs(); System.out.println("Creating parent directory... " + parentFile.getAbsolutePath()); byte[] buffer = new byte[1024]; FileOutputStream fos = new FileOutputStream(file); BufferedOutputStream out = new BufferedOutputStream(fos); int len;//from w w w . j a v a 2s .c om try { while ((len = in.read(buffer)) >= 0) { out.write(buffer, 0, len); } } catch (IOException ex) { } finally { try { in.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { out.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }