List of usage examples for java.io File mkdir
public boolean mkdir()
From source file:Main.java
/** * Get the application folder on the SD Card. Create it if not present. * @return The application folder.// ww w . ja v a2 s . co m */ public static File getApplicationFolder() { File root = Environment.getExternalStorageDirectory(); if (root.canWrite()) { File folder = new File(root, APPLICATION_FOLDER); if (!folder.exists()) { folder.mkdir(); } return folder; } else { return null; } }
From source file:com.elit2.app.model.FileUpload.java
public static boolean proccessFile(String path, FileItemStream item) { try {/* www . ja va 2 s . co m*/ File f = new File(path + File.separator + "images"); if (!f.exists()) { f.mkdir(); } File savedFile = new File(f.getAbsolutePath() + File.separator + item.getName()); FileOutputStream fos = new FileOutputStream(savedFile); InputStream is = item.openStream(); int x = 0; byte[] b = new byte[1024]; while ((x = is.read()) != -1) { fos.write(b, 0, x); } fos.flush(); fos.close(); return true; } catch (Exception ex) { ex.printStackTrace(); } return false; }
From source file:Main.java
public static File getTempFile(Context context) { //it will return /sdcard/image.tmp final File path = new File(Environment.getExternalStorageDirectory(), context.getPackageName()); if (!path.exists()) { path.mkdir(); }/* w w w .j a v a 2s .c o m*/ return new File(path, "image.jpg"); }
From source file:Main.java
public static void createCSV() { File folder = new File(Environment.getExternalStorageDirectory() + "/adspammer"); if (!folder.exists()) folder.mkdir(); String filename = folder.toString() + "/" + "log.csv"; File csvFile = new File(filename); if (!csvFile.exists()) try {//w w w. j a v a2 s . c o m csvFile.createNewFile(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static File getTmpFile() { File fileDirectory = new File(extStorageDirectory); if (!fileDirectory.exists()) { fileDirectory.mkdir(); }//from w w w . ja v a 2s. c o m return new File(tmpImageFile); }
From source file:Main.java
/** * Get a writeable cache directory for saving cache files * * @param context//from w w w. java 2 s . co m * @return file directory or null */ public static File getApplicationCacheDirectory(Context context) { File directory = context.getFilesDir(); String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { File externalDirectory = context.getExternalFilesDir(null); if (externalDirectory != null) { directory = externalDirectory; } } File cacheDirectory = new File(directory, CACHE_DIRECTORY); if (!cacheDirectory.exists()) { cacheDirectory.mkdir(); } return cacheDirectory; }
From source file:Main.java
public static File getTempFilePath(Context context, String str_profile) { // it will return /sdcard/image.tmp final File path = new File(Environment.getExternalStorageDirectory(), context.getPackageName()); if (!path.exists()) { path.mkdir(); }//from ww w. j av a 2s . co m return new File(path, str_profile); }
From source file:Main.java
static File make_tmpdir(Context context, SQLiteDatabase db) throws Exception { File extdir = Environment.getExternalStorageDirectory(); File tmp_top = new File(extdir, "tmp_LongText"); if (!tmp_top.exists()) { if (!tmp_top.mkdir()) throw new Exception("cannot create directory: " + tmp_top.getPath()); }/*from w ww . j a va 2 s. c om*/ if (!tmp_top.canWrite()) throw new Exception("missing permission to write to " + tmp_top.getPath()); File tmpdir; Random r = new Random(); do { tmpdir = new File(tmp_top, String.format("%d", r.nextInt())); } while (tmpdir.exists()); if (!tmpdir.mkdir()) throw new Exception("cannot create directory: " + tmp_top.getPath()); if (!tmpdir.canWrite()) throw new Exception("missing permission to write to " + tmp_top.getPath()); ContentValues v = new ContentValues(); v.put("pid", Process.myPid()); v.put("tmpdir", tmpdir.getPath()); v.put("ctime", System.currentTimeMillis()); db.insert("tmpdir", null, v); return tmpdir; }
From source file:awshamondsidefunctions.MakeHamondDir.java
public static void make() throws IOException { File dir = new File("/mnt/Hamond"); if (dir.exists()) { FileUtils.deleteDirectory(dir);//from w ww .j a v a 2 s . c o m } dir.mkdir(); }
From source file:com.springsource.open.db.BaseDatasourceTests.java
@BeforeClass @AfterClass//from w w w. j av a2 s. c o m public static void clearLog() { // Ensure that Atomikos logging directory exists File dir = new File("atomikos"); if (!dir.exists()) { dir.mkdir(); } // ...and delete any stale locks (this would be a sign of a crash) File tmlog = new File("atomikos/tmlog.lck"); if (tmlog.exists()) { tmlog.delete(); } }