List of usage examples for java.io File mkdir
public boolean mkdir()
From source file:com.zeusky.star.star.java
public static void createSharePicDir() { boolean sdCardExist = Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED); if (!sdCardExist) { Toast.makeText(m_instance, "???", Toast.LENGTH_SHORT).show(); } else {//from ww w. j av a2s. c o m String dir = Environment.getExternalStorageDirectory() + File.separator + "zeusky.popstar"; Log.d("shareSDK", "I am need this dir " + dir); File snapShotDir = new File(dir); if (!snapShotDir.exists()) { snapShotDir.mkdir(); } methodsRun.injectOtherDir(dir + File.separator); } }
From source file:org.crazydog.util.spring.FileSystemUtils.java
/** * Actually copy the contents of the {@code src} file/directory * to the {@code dest} file/directory.//w w w.j a v a2 s . c o m * * @param src the source directory * @param dest the destination directory * @throws IOException in the case of I/O errors */ private static void doCopyRecursively(File src, File dest) throws IOException { if (src.isDirectory()) { dest.mkdir(); File[] entries = src.listFiles(); if (entries == null) { throw new IOException("Could not list files in directory: " + src); } for (File entry : entries) { doCopyRecursively(entry, new File(dest, entry.getName())); } } else if (src.isFile()) { try { dest.createNewFile(); } catch (IOException ex) { IOException ioex = new IOException("Failed to create file: " + dest); ioex.initCause(ex); throw ioex; } FileCopyUtils.copy(src, dest); } else { // Special File handle: neither a file not a directory. // Simply skip it when contained in nested directory... } }
From source file:com.bellman.bible.service.common.FileManager.java
public static boolean copyFile(File fromFile, File toFile) { boolean ok = false; try {/* ww w .j a v a2 s .com*/ // don't worry if tofile exists, allow overwrite if (fromFile.exists()) { //ensure the target dir exists or FileNotFoundException is thrown creating dst FileChannel File toDir = toFile.getParentFile(); toDir.mkdir(); long fromFileSize = fromFile.length(); log.debug("Source file length:" + fromFileSize); if (fromFileSize > CommonUtils.getFreeSpace(toDir.getPath())) { // not enough room on SDcard ok = false; } else { // move the file FileInputStream srcStream = new FileInputStream(fromFile); FileChannel src = srcStream.getChannel(); FileOutputStream dstStream = new FileOutputStream(toFile); FileChannel dst = dstStream.getChannel(); try { dst.transferFrom(src, 0, src.size()); ok = true; } finally { src.close(); dst.close(); srcStream.close(); dstStream.close(); } } } else { // fromfile does not exist ok = false; } } catch (Exception e) { log.error("Error moving file to sd card", e); } return ok; }
From source file:com.netflix.imfutility.itunes.asset.AudioAssetProcessorTest.java
@BeforeClass public static void setupAll() throws IOException { // create both working directory and logs folder. FileUtils.deleteDirectory(TemplateParameterContextCreator.getWorkingDir()); File workingDir = TemplateParameterContextCreator.getWorkingDir(); if (!workingDir.mkdir()) { throw new RuntimeException("Could not create a working dir within tmp folder"); }/*from ww w .j a va 2s. c om*/ }
From source file:Main.java
private static Uri getUriFromAsset(Context mContext, String path) { File dir = mContext.getExternalCacheDir(); if (dir == null) { Log.e(TAG, "Missing external cache dir"); return Uri.EMPTY; }/*from w w w. j av a 2 s . com*/ String resPath = path.replaceFirst("file:/", "www"); String fileName = resPath.substring(resPath.lastIndexOf('/') + 1); String storage = dir.toString() + STORAGE_FOLDER; if (fileName == null || fileName.isEmpty()) { Log.e(TAG, "Filename is missing"); return Uri.EMPTY; } File file = new File(storage, fileName); FileOutputStream outStream = null; InputStream inputStream = null; try { File fileStorage = new File(storage); if (!fileStorage.mkdir()) Log.e(TAG, "Storage directory could not be created: " + storage); AssetManager assets = mContext.getAssets(); outStream = new FileOutputStream(file); inputStream = assets.open(resPath); copyFile(inputStream, outStream); outStream.flush(); outStream.close(); return Uri.fromFile(file); } catch (FileNotFoundException e) { Log.e(TAG, "File not found: assets/" + resPath); } catch (IOException ioe) { Log.e(TAG, "IOException occured"); } catch (SecurityException secEx) { Log.e(TAG, "SecurityException: directory creation denied"); } finally { try { if (inputStream != null) { inputStream.close(); } if (outStream != null) { outStream.flush(); outStream.close(); } } catch (IOException ioe) { Log.e(TAG, "IOException occured while closing/flushing streams"); } } return Uri.EMPTY; }
From source file:Main.java
public static void creatFile(String fileName) { if (sdState.equals(Environment.MEDIA_MOUNTED)) { File file = new File( Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + fileName); if (!file.exists()) { file.mkdir(); }/*from w w w . j a v a 2s. com*/ } }
From source file:Main.java
/** * Creates a temporary file with the specified prefix and extension. * // w w w.j a v a 2 s .c om * @param part * the prefix for the file * @param ext * the extension for the file * @param context * the application's context * @return the created File * @throws Exception */ private static File createTemporaryFile(String part, String ext, Context context) throws Exception { File tempDir = Environment.getExternalStorageDirectory(); tempDir = new File(tempDir.getAbsolutePath() + "/bv-temp/"); if (!tempDir.exists()) { tempDir.mkdir(); } return File.createTempFile(part, ext, tempDir); }
From source file:eu.nubomedia.nubomedia_kurento_health_communicator_android.kc_and_communicator.services.LogService.java
public static boolean sendLogToServer(Context context) { String version = context.getString(R.string.version); String buildNumber = context.getString(R.string.build_number); log.debug("VERSION: {}, BUILD NUMBER: {}", new Object[] { version, buildNumber }); log.debug("sendLogToServer..."); File root = Environment.getExternalStorageDirectory(); File dir = new File(root + "/" + LOG_DIR); if (!dir.exists()) { if (!dir.mkdir()) { log.error("Cannot create dir {}", dir); }/* w ww . j a v a 2s . c om*/ } File file; try { file = new File(root + "/" + LOG_DIR, Long.toString(System.currentTimeMillis())); log.debug("LOG FILE NAME: {}", file.getAbsolutePath()); Runtime.getRuntime().exec("logcat -d -v time -f " + file.getAbsolutePath()); } catch (IOException e) { log.error("Cannot read logcat", e); return false; } String channelId = ChannelService.getChannelId(context); try { HttpResp<Void> resp = HttpManager.sendPostVoid(context, context.getString(R.string.url_log, channelId), file); int code = resp.getCode(); if (code == HttpStatus.SC_FORBIDDEN || code == HttpStatus.SC_BAD_REQUEST) { throw new KurentoCommandException("Command error (" + code + ")"); } return code == HttpStatus.SC_CREATED; } catch (Exception e) { log.error("Cannot send log", e); return false; } }
From source file:com.microsoft.azure.hdinsight.util.HDInsightJobViewUtils.java
public static void unzip(String zipFilePath, String destDirectory) throws IOException { File destDir = new File(destDirectory); if (!destDir.exists()) { destDir.mkdir(); }// www . j a v a2 s . com ZipInputStream zipIn = new ZipInputStream(new FileInputStream(zipFilePath)); ZipEntry entry = zipIn.getNextEntry(); while (entry != null) { String filePath = destDirectory + File.separator + entry.getName(); if (!entry.isDirectory()) { extractFile(zipIn, filePath); } else { File dir = new File(filePath); dir.mkdir(); } zipIn.closeEntry(); entry = zipIn.getNextEntry(); } zipIn.close(); }
From source file:Main.java
private static File getDirectoryBoards() { File file = new File(Environment.getExternalStorageDirectory(), DIR_BOARDS_EXTERNAL);//from w w w. ja v a 2s . c om if (!file.exists()) { file.mkdir(); } return file; }