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 File getOutputMediaFile(int type, Context c) { File mediaStorageDir = new File(c.getApplicationContext().getExternalFilesDir(null).getAbsolutePath()); if (!mediaStorageDir.exists()) { if (!mediaStorageDir.mkdirs()) { Log.d("MyCameraApp", "failed to create directory"); return null; }//from ww w. j a v a 2 s.c o m } // Create a media file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); File mediaFile; if (type == MEDIA_TYPE_IMAGE) { mediaFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_" + timeStamp + ".jpg"); } else if (type == MEDIA_TYPE_AUDIO) { mediaFile = new File(mediaStorageDir.getPath() + File.separator + "VID_" + timeStamp + ".3gp"); } else { return null; } return mediaFile; }
From source file:Main.java
public static Bitmap convertToMutable(Bitmap srcBitmap, String cacheDirPath, String tempFileName) { try {/* w w w . ja va2s . c o m*/ // this is the file going to use temporally to save the bytes. // This file will not be a image, it will store the raw image data. int index = tempFileName.lastIndexOf("."); if (index != -1) tempFileName = tempFileName.substring(0, index); File file = new File(cacheDirPath + File.separator + tempFileName + ".tmp"); // Open an RandomAccessFile // Make sure you have added uses-permission // android:name="android.permission.WRITE_EXTERNAL_STORAGE" // into AndroidManifest.xml file RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw"); // get the width and height of the source bitmap. int width = srcBitmap.getWidth(); int height = srcBitmap.getHeight(); Config type = srcBitmap.getConfig(); // Copy the byte to the file // Assume source bitmap loaded using options.inPreferredConfig = // Config.ARGB_8888; FileChannel channel = randomAccessFile.getChannel(); MappedByteBuffer map = channel.map(MapMode.READ_WRITE, 0, srcBitmap.getRowBytes() * height); srcBitmap.copyPixelsToBuffer(map); // recycle the source bitmap, this will be no longer used. srcBitmap.recycle(); System.gc();// try to force the bytes from the imgIn to be released // Create a new bitmap to load the bitmap again. Probably the memory // will be available. srcBitmap = Bitmap.createBitmap(width, height, type); map.position(0); // load it back from temporary srcBitmap.copyPixelsFromBuffer(map); // close the temporary file and channel , then delete that also channel.close(); randomAccessFile.close(); // delete the temp file file.delete(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return srcBitmap; }
From source file:Main.java
public static File createFile(Context context) { File file;// w w w. ja va 2 s . com if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { String timeStamp = String.valueOf(new Date().getTime()); file = new File(Environment.getExternalStorageDirectory() + File.separator + timeStamp + ".jpg"); } else { File cacheDir = context.getCacheDir(); String timeStamp = String.valueOf(new Date().getTime()); file = new File(cacheDir, timeStamp + ".jpg"); } return file; }
From source file:Main.java
public static File getLocalBackupFolder(Context context) { File rootFolder = new File(context.getExternalFilesDir(null) + File.separator + "backup"); rootFolder.mkdirs();// w ww. ja v a2 s .co m return rootFolder; }
From source file:Main.java
public static Uri getOutputMediaFileUri() { File mediaStorageDir = new File(getCachePath()); if (!mediaStorageDir.exists()) { if (!mediaStorageDir.mkdirs()) { return null; }/*from w w w .j a v a 2 s .c o m*/ } String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); File mediaFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_" + timeStamp + ".jpg"); return Uri.fromFile(mediaFile); }
From source file:Main.java
/** * Get SDCard cache dir./*from ww w.j ava 2s . c o m*/ * * @param context * @return */ public static String getSdCacheDir(Context context) { if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { java.io.File fExternalStorageDirectory = Environment.getExternalStorageDirectory(); java.io.File autonaviDir = new java.io.File(fExternalStorageDirectory, "move"); boolean result = false; if (!autonaviDir.exists()) { result = autonaviDir.mkdir(); } java.io.File minimapDir = new java.io.File(autonaviDir, "offlineMap"); if (!minimapDir.exists()) { result = minimapDir.mkdir(); } return minimapDir.toString() + File.separator; } else { return ""; } }
From source file:Main.java
static String getFileName(Context context, Uri uri) { String result = null;/*w ww. jav a 2 s. c o m*/ if (uri.getScheme().equals("content")) { Cursor cursor = context.getContentResolver().query(uri, null, null, null, null); try { if (cursor != null && cursor.moveToFirst()) { result = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)); } } catch (Exception e) { e.printStackTrace(); } finally { if (cursor != null) { cursor.close(); } } } if (result == null) { result = uri.getPath(); int cut = result.lastIndexOf(File.separator); if (cut != -1) { result = result.substring(cut + 1); } } return result; }
From source file:Main.java
public static boolean fileExists(Context context, String fileName) { return new File(context.getFilesDir() + File.separator + fileName).exists(); }
From source file:Main.java
public static String getLibraryDirectory() { return Environment.getExternalStorageDirectory() + File.separator + "MicDroid" + File.separator + "recordings"; }
From source file:config.ResourceUtils.java
/** * Gets a resource by its relative path. If the resource is not found on the * file system, the classpath is searched. If nothing is found, null is * returned.//from w w w . j a v a 2s .c o m * * @param fileName the name of the resource * @return the found resource */ public static Resource getResourceByRelativePath(String fileName) { Resource resource = new FileSystemResource(RESOURCES_FOLDER + File.separator + fileName); if (!resource.exists()) { //try to find it on the classpath resource = new ClassPathResource(fileName); if (!resource.exists()) { // making sure to run on Netbeans.. resource = new FileSystemResource("src" + File.separator + "main" + File.separator + RESOURCES_FOLDER + File.separator + fileName); if (!resource.exists()) { resource = null; } } } return resource; }