List of usage examples for java.io File getAbsolutePath
public String getAbsolutePath()
From source file:Main.java
private static String toPath(File root, File dir) { String path = dir.getAbsolutePath(); path = path.substring(root.getAbsolutePath().length()).replace(File.separatorChar, '/'); if (path.startsWith("/")) { path = path.substring(1);//from w ww .j a va2 s .c o m } if (dir.isDirectory() && !path.endsWith("/")) { path += "/"; } return path; }
From source file:Main.java
public static boolean restoreFromBackup(File f) { File backup = new File(f.getAbsolutePath() + ".good.bak.2"); if (f.exists()) f.delete();/*from ww w . ja v a2s. c o m*/ if (backup.exists()) { if (backup.renameTo(f)) return true; } return false; }
From source file:Main.java
static Bitmap get(File cache) { return BitmapFactory.decodeFile(cache.getAbsolutePath()); }
From source file:Main.java
/** * Set a track as complete.//from ww w . j a va 2 s . c o m * @param file File * @return True if the operation was successful */ public static boolean setComplete(File file) { return file.renameTo(new File(file.getAbsolutePath() + ".complete")); }
From source file:Main.java
public static Uri getAudioContentUri(Context context, File file) { String filePath = file.getAbsolutePath(); Cursor cursor = context.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, new String[] { MediaStore.Audio.Media._ID }, MediaStore.Audio.Media.DATA + "=?", new String[] { filePath }, null); cursor.moveToFirst();/*from ww w . ja va2 s .c om*/ int id = cursor.getInt(cursor.getColumnIndex(MediaStore.MediaColumns._ID)); Uri baseUri = Uri.parse("content://media/external/audio/media"); return Uri.withAppendedPath(baseUri, "" + id); }
From source file:Main.java
/** * Build an URL from a file name./* ww w . j a v a 2 s . c o m*/ * * @param file a local file name * @return an URL with the <tt>file</tt> scheme */ @NonNull public static String fileToUrl(final File file) { return FILE_PROTOCOL + file.getAbsolutePath(); }
From source file:Main.java
public static String createFile(String parent, String fileName) { File dir = new File(parent); if (!dir.exists()) { dir.mkdirs();//from www . j av a2 s . co m } File file = new File(dir, fileName); return file.getAbsolutePath(); }
From source file:Main.java
public static String generateFileContentType(File f) { int dotIndex = f.getAbsolutePath().lastIndexOf("."); if (dotIndex < 0) { return "application/octet-stream"; }/* w w w. j a v a2 s .c o m*/ String suffix = f.getAbsolutePath().substring(dotIndex).toLowerCase(); if ("jpg".equals(suffix) || "jpeg".equals(suffix)) return "image/jpeg"; else if ("png".equals(suffix) || "gif".equals(suffix)) return "image/" + suffix; else if ("mp3".equals(suffix) || "mpeg".equals(suffix)) return "audio/mpeg"; else if ("mp4".equals(suffix) || "ogg".equals(suffix)) return "audio/" + suffix; else return "application/octet-stream"; }
From source file:Main.java
/** * Loads a Bitmap from a {@link File}/*from w ww .j a v a 2s .c om*/ * * @param file {@link File} to load the {@link Bitmap} from * @return Bitmap from the file-pointer */ public static Bitmap fromFile(File file) { return BitmapFactory.decodeFile(file.getAbsolutePath()); }
From source file:Main.java
private static void file(String path) { File destDir = new File(path); Log.d(TAG, destDir.getAbsolutePath()); if (!destDir.exists()) { Log.d(TAG, "false"); destDir.mkdirs();/* w ww. j a v a 2s .c o m*/ } }