List of usage examples for java.io File mkdir
public boolean mkdir()
From source file:com.linkedin.parseq.zk.server.ZKServer.java
private static File createTempDir(String suffix) { File parent = new File(System.getProperty("java.io.tmpdir")); String baseName = System.currentTimeMillis() + "."; for (int counter = 0; counter < 10; ++counter) { File tempDir = new File(parent, baseName + counter + "." + suffix); if (tempDir.mkdir()) { return tempDir; }/*from w w w. jav a2 s .c o m*/ } throw new IllegalStateException( "Failed to create directory within 10 attempts (tried " + baseName + "0 to " + baseName + 9 + ')'); }
From source file:net.refractions.udig.document.source.ShpDocUtils.java
/** * Copies a read-only copy of the old file into new file directory. * /*from w w w . ja v a 2 s. c o m*/ * @param oldFile * @param newFileDir * @return new file */ public static File copyFile(File oldFile, File newFileDir) { try { if (!newFileDir.exists()) { newFileDir.mkdir(); } final File newFile = new File(newFileDir, oldFile.getName()); if (!newFile.exists()) { FileUtils.copyFileToDirectory(oldFile, newFileDir); newFile.setReadOnly(); } return newFile; } catch (IOException e) { // Should not happen e.printStackTrace(); } return null; }
From source file:edu.unc.lib.dl.util.ZipFileUtil.java
/** * Create a temporary directory, unzip the contents of the given zip file to * it, and return the directory./*www .j a v a 2s. c o m*/ * * If anything goes wrong during this process, clean up the temporary * directory and throw an exception. */ public static File unzipToTemp(File zipFile) throws IOException { // get a temporary directory to work with File tempDir = File.createTempFile("ingest", null); tempDir.delete(); tempDir.mkdir(); tempDir.deleteOnExit(); log.info("Unzipping to temporary directory: " + tempDir.getPath()); try { unzip(new FileInputStream(zipFile), tempDir); return tempDir; } catch (IOException e) { // attempt cleanup, then re-throw org.apache.commons.io.FileUtils.deleteDirectory(tempDir); throw e; } }
From source file:edu.unc.lib.dl.util.ZipFileUtil.java
/** * Create a temporary directory, unzip the contents of the given zip file to * it, and return the directory./*ww w . j av a2s. c om*/ * * If anything goes wrong during this process, clean up the temporary * directory and throw an exception. */ public static File unzipToTemp(InputStream zipStream) throws IOException { // get a temporary directory to work with File tempDir = File.createTempFile("ingest", null); tempDir.delete(); tempDir.mkdir(); tempDir.deleteOnExit(); log.debug("Unzipping to temporary directory: " + tempDir.getPath()); try { unzip(zipStream, tempDir); return tempDir; } catch (IOException e) { // attempt cleanup, then re-throw org.apache.commons.io.FileUtils.deleteDirectory(tempDir); throw e; } }
From source file:jodtemplate.util.Utils.java
public static void createRequiredFolders(final File targetFolder) throws IOException { createParentFolders(targetFolder);/*from ww w.j a v a2 s .com*/ if (!targetFolder.exists()) { final boolean dirCreated = targetFolder.mkdir(); if (!dirCreated) { throw new IOException(); } } }
From source file:Main.java
public static String getSdCacheDir(Context context) { if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { if (true) { Context appContext = context.getApplicationContext(); File amap = appContext.getExternalFilesDir("offlineMap"); return amap.getAbsolutePath() + "/"; } else {/* ww w .ja va2 s.com*/ File fExternalStorageDirectory = Environment.getExternalStorageDirectory(); File autonaviDir = new File(fExternalStorageDirectory, "amapsdk"); boolean result = false; if (!autonaviDir.exists()) { result = autonaviDir.mkdir(); } File minimapDir = new File(autonaviDir, "offlineMap"); if (!minimapDir.exists()) { result = minimapDir.mkdir(); } return minimapDir.toString() + "/"; } } else { return ""; } }
From source file:Util.java
public static void createHome() throws Exception { File ch = new File(System.getProperty("user.home") + File.separator + ".dataform"); if (!ch.exists()) { if (!ch.mkdir()) throw new Exception("Failed to create the dataform configuration directory"); }//from www .ja v a2s . c om }
From source file:edu.cornell.med.icb.io.TestResourceFinder.java
/** * Make the temp dir outside of existing directory. */// w w w.j a va2 s .c o m private static void makeTmpDir() { final File tmpDir = new File("/tmp/"); if (tmpDir.exists()) { return; } tmpDir.mkdir(); }
From source file:Main.java
/** * Returns individual application cache directory (for only image caching from ImageLoader). Cache directory will be * created on SD card <i>("/Android/data/[app_package_name]/cache/uil-images")</i> if card is mounted and app has * appropriate permission. Else - Android defines cache directory on device's file system. * * @param context Application context//www . j a v a 2 s.com * @param cacheDir Cache directory path (e.g.: "AppCacheDir", "AppDir/cache/images") * @return Cache {@link File directory} */ public static File getIndividualCacheDirectory(Context context, String cacheDir) { File appCacheDir = getCacheDirectory(context); File individualCacheDir = new File(appCacheDir, cacheDir); if (!individualCacheDir.exists()) { if (!individualCacheDir.mkdir()) { individualCacheDir = appCacheDir; } } return individualCacheDir; }
From source file:org.meshpoint.anode.util.ModuleUtils.java
private static boolean copyDir(File src, File dest) { dest.mkdir(); for (String child : src.list()) { boolean result = copyFile(new File(src, child), new File(dest, child)); if (!result) { return false; }/*w ww. java2s. co m*/ } return true; }