List of usage examples for java.io File separator
String separator
To view the source code for java.io File separator.
Click Source Link
From source file:Main.java
public static String getDiskCacheDir(Context context, String dirName) { final String cachePath = Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) ? context.getExternalCacheDir().getPath() : context.getCacheDir().getPath(); return cachePath + File.separator + dirName; }
From source file:Main.java
/** * Saves a Bitmap object to disk for analysis. * * @param bitmap The bitmap to save./*from w w w . jav a2 s . c o m*/ */ public static void saveBitmap(final Bitmap bitmap) { final String root = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "tensorflow"; //LOGGER.i("Saving %dx%d bitmap to %s.", bitmap.getWidth(), bitmap.getHeight(), root); final File myDir = new File(root); if (!myDir.mkdirs()) { //LOGGER.i("Make dir failed"); } final String fname = "preview.png"; final File file = new File(myDir, fname); if (file.exists()) { file.delete(); } try { final FileOutputStream out = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.PNG, 99, out); out.flush(); out.close(); } catch (final Exception e) { //LOGGER.e(e, "Exception!"); } }
From source file:Main.java
public static boolean writeToFile(Context ctx, String strContent, String filename) { boolean bReturn = true; FileOutputStream osw = null;/*from ww w . j a v a2s .c om*/ try { //Make sub directories if needed String[] split = filename.split(File.separator); String file = split[split.length - 1]; String path = filename.substring(0, filename.indexOf(file)); if (path != "") new File(ctx.getFilesDir() + File.separator + path).mkdirs(); File outputFile = new File(ctx.getFilesDir() + File.separator + filename); osw = new FileOutputStream(outputFile); osw.write(strContent.getBytes()); osw.close(); } catch (Exception e) { e.printStackTrace(); bReturn = false; } finally { try { if (osw != null) osw.close(); } catch (IOException e) { e.printStackTrace(); } } return bReturn; }
From source file:Main.java
public static Uri createUri(String foldername) { String storageState = Environment.getExternalStorageState(); if (storageState.equals(Environment.MEDIA_MOUNTED)) { final File root = new File( Environment.getExternalStorageDirectory() + File.separator + foldername + File.separator); root.mkdirs();/*from w w w . ja v a2s. c om*/ final String fname = getUniqueImageFilename(foldername); final File sdImageMainDirectory = new File(root, fname); return Uri.fromFile(sdImageMainDirectory); } return null; }
From source file:Main.java
/** * Read xml Signature by given name from local Signature store * @param filename// www . ja v a2 s .c o m * @return File object with xml signature * @throws Exception when file doesn't exists */ public static File getSignatureXMLFile(String filename) throws IOException { File file = new File(baseDir + File.separator + filename); if (!file.exists()) throw new IOException("given xml signature file doesn't exist :" + filename); return file; }
From source file:Main.java
public static String getAbsolutePathFromNoStandardUri(Uri mUri) { String filePath = null;/*w w w .ja v a2 s. c o m*/ String mUriString = mUri.toString(); mUriString = Uri.decode(mUriString); String pre1 = "file://" + SDCARD + File.separator; String pre2 = "file://" + SDCARD_MNT + File.separator; if (mUriString.startsWith(pre1)) { filePath = Environment.getExternalStorageDirectory().getPath() + File.separator + mUriString.substring(pre1.length()); } else if (mUriString.startsWith(pre2)) { filePath = Environment.getExternalStorageDirectory().getPath() + File.separator + mUriString.substring(pre2.length()); } return filePath; }
From source file:Main.java
public static String storageDir(Context context) { if (useExternalStorage) { return extStorageDir(context); }//from ww w. ja v a 2 s . c o m File mediaStorageDir = context.getFilesDir(); return mediaStorageDir.getPath() + File.separator; }
From source file:Main.java
public static boolean delAllFile(String path) { boolean flag = false; File file = new File(path); if (!file.exists()) { return flag; }//from w ww. ja v a 2 s . co m if (!file.isDirectory()) { return flag; } String[] tempList = file.list(); File temp = null; for (int i = 0; i < tempList.length; i++) { if (path.endsWith(File.separator)) { temp = new File(path + tempList[i]); } else { temp = new File(path + File.separator + tempList[i]); } if (temp.isFile()) { temp.delete(); } if (temp.isDirectory()) { delAllFile(path + "/" + tempList[i]); flag = true; } } return flag; }
From source file:generator.Utils.java
public static File join(String headPath, String tailPath) { return new File(headPath + File.separator + tailPath); }
From source file:Main.java
public static String readFile(Context ctx, String filename) { FileInputStream fis = null;/*from ww w . jav a 2s . c om*/ String line = null; StringBuilder sb = new StringBuilder(); try { fis = new FileInputStream(ctx.getFilesDir() + File.separator + filename); InputStreamReader inputStreamReader = new InputStreamReader(fis); @SuppressWarnings("resource") BufferedReader bufferedReader = new BufferedReader(inputStreamReader); while ((line = bufferedReader.readLine()) != null) { sb.append(line); } } catch (Exception e) { //e.printStackTrace(); return null; } finally { try { if (fis != null) fis.close(); } catch (IOException e) { return null; } } return sb.toString(); }