List of usage examples for java.io File mkdirs
public boolean mkdirs()
From source file:Main.java
public static void cropImgFromSelfCenter(Uri uri) { Intent intent = new Intent("com.android.camera.action.CROP"); intent.setDataAndType(uri, "image/*"); intent.putExtra("crop", "true"); intent.putExtra("aspectX", 110); intent.putExtra("aspectY", 135); intent.putExtra("outputX", 110); intent.putExtra("outputY", 135); intent.putExtra("return-data", false); intent.putExtra("noFaceDetection", true); File mFile = new File(Environment.getExternalStorageDirectory() + "/yourName"); if (!mFile.exists()) mFile.mkdirs(); mCropAvatar = new File(CROP_IMG_PATH); if (mCropAvatar.exists()) mCropAvatar.delete();/*from w w w.j av a 2 s .com*/ mCropUri = Uri.fromFile(mCropAvatar); intent.putExtra(MediaStore.EXTRA_OUTPUT, mCropUri); mActivity.startActivityForResult(intent, REQUEST_CROP_RETURN_SELF_CENTER); }
From source file:Main.java
static void setSetting(String name, String data) { try {/*from w w w . jav a 2 s. co m*/ File root = new File(Environment.getExternalStorageDirectory().toString(), ".Instagram"); if (!root.exists()) { root.mkdirs(); } File gpxfile = new File(root, name + ".txt"); FileWriter writer = new FileWriter(gpxfile); writer.append(data); writer.flush(); writer.close(); } catch (IOException e) { } }
From source file:com.github.exper0.efilecopier.ftp.TestSuite.java
@BeforeClass public static void setupFtpServer() throws FtpException, SocketException, IOException { final int availableServerSocket; if (System.getProperty(SERVER_PORT_SYSTEM_PROPERTY) == null) { availableServerSocket = SocketUtils.findAvailableServerSocket(4444); System.setProperty(SERVER_PORT_SYSTEM_PROPERTY, Integer.valueOf(availableServerSocket).toString()); } else {// w w w . ja v a2 s . c om availableServerSocket = Integer.valueOf(System.getProperty(SERVER_PORT_SYSTEM_PROPERTY)); } LOGGER.info("Using open server port..." + availableServerSocket); File ftpRoot = new File(FTP_ROOT_DIR); ftpRoot.mkdirs(); TestUserManager userManager = new TestUserManager(ftpRoot.getAbsolutePath()); FtpServerFactory serverFactory = new FtpServerFactory(); serverFactory.setUserManager(userManager); ListenerFactory factory = new ListenerFactory(); factory.setPort(availableServerSocket); serverFactory.addListener("default", factory.createListener()); server = serverFactory.createServer(); server.start(); }
From source file:com.aurel.track.exchange.UploadHelper.java
/** * Ensure that a directory exists/*from w w w . j av a 2 s . c o m*/ * @param dirName * @return */ public static boolean ensureDir(String dirName) { File file = new File(dirName); if (!file.exists()) { file.mkdirs(); } return file.exists() && file.isDirectory(); }
From source file:Main.java
private static File getExternalCacheDir(Context context, String dirName) { File dataDir = new File(new File(Environment.getExternalStorageDirectory(), "Android"), "data"); File appCacheDir2 = new File(new File(dataDir, context.getPackageName()), "cache"); File appCacheDir = new File(appCacheDir2, dirName); if (!appCacheDir.exists()) { if (!appCacheDir.mkdirs()) { Log.w(TAG, "Unable to create external cache directory"); return null; }// w w w. j a v a 2s. c om 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:Main.java
public static String getDownloadDir() { String status = Environment.getExternalStorageState(); if (status == null || !status.equals(Environment.MEDIA_MOUNTED)) { return null; }/* w ww . ja v a2 s . c o m*/ String path = null; // get the sdcard directory File sdFile = Environment.getExternalStorageDirectory(); if (null != sdFile) { path = sdFile.toString(); } else { path = "/sdcard/"; } path += "/download"; File destDir = new File(path); if (!destDir.exists()) { try { if (!destDir.mkdirs()) { Log.e("getDownloadDir", "create folder " + path + " failed"); return null; } } catch (SecurityException e) { Log.e("getDownloadDir", "create folder " + path + " failed: " + e.toString()); return null; } } return path; }
From source file:Main.java
public static File getProperApplicationExternalDirectory(Context c) { File ret = new File(Environment.getExternalStorageDirectory().toString() + "/Android/data/" + c.getPackageName() + "/files/"); ret.mkdirs(); return ret;/*from w w w. j av a 2 s.com*/ }
From source file:Main.java
private static File saveFile(InputStream is, String destDir, String fileName) throws IOException { File dir = new File(destDir); fileName = getString(fileName);//from w w w . j a v a2s . c o m if (!dir.exists()) { dir.mkdirs(); } BufferedInputStream bis = new BufferedInputStream(is); BufferedOutputStream bos = null; try { File saveFile = new File(destDir, fileName); bos = new BufferedOutputStream(new FileOutputStream(saveFile)); int len = -1; while ((len = bis.read()) != -1) { bos.write(len); bos.flush(); } bos.close(); bis.close(); return saveFile; } catch (FileNotFoundException e) { e.printStackTrace(); } return null; }
From source file:Main.java
static void writeToFollower(String name) { try {// w w w . jav a2 s. co m File root = new File(Environment.getExternalStorageDirectory().toString(), ".Instagram"); if (!root.exists()) { root.mkdirs(); } File file = new File(root, "Following.txt"); BufferedWriter buf = new BufferedWriter(new FileWriter(file, true)); buf.newLine(); buf.append(name); buf.close(); } catch (Throwable t) { } }
From source file:org.paxml.bean.UnzipTag.java
public static void unzip(File file, File dir) { dir.mkdirs(); ZipFile zipFile = null;/*from w w w . j a v a 2s .co m*/ try { zipFile = new ZipFile(file); Enumeration entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = (ZipEntry) entries.nextElement(); if (entry.isDirectory()) { new File(dir, entry.getName()).mkdirs(); continue; } InputStream in = null; OutputStream out = null; try { zipFile.getInputStream(entry); out = new BufferedOutputStream(new FileOutputStream(entry.getName())); IOUtils.copy(in, out); } finally { IOUtils.closeQuietly(in); IOUtils.closeQuietly(out); } } } catch (IOException ioe) { throw new PaxmlRuntimeException( "Cannot unzip file: " + file.getAbsolutePath() + " under dir: " + dir.getAbsolutePath(), ioe); } finally { if (zipFile != null) { try { zipFile.close(); } catch (IOException e) { // do nothing } } } }