List of usage examples for java.io File getAbsolutePath
public String getAbsolutePath()
From source file:Main.java
private static String createDir(String dirPath) { try {/* w w w .ja va 2 s . c o m*/ File dir = new File(dirPath); if (!dir.exists()) { dir.mkdirs(); } return dir.getAbsolutePath(); } catch (Exception e) { e.printStackTrace(); } return dirPath; }
From source file:Main.java
/** * Returns the amount of storage currently available in the cache. * * @param dir The cache directory path name. * @return The amount of storage available in bytes. *//* w ww . j a v a 2 s . c om*/ public static long calculateDiskCacheSize(File dir) { long size = MIN_DISK_CACHE_SIZE; try { StatFs statFs = new StatFs(dir.getAbsolutePath()); long available = statFs.getBlockCountLong() * statFs.getBlockSizeLong(); // Target 2% of the total space. size = available * MAX_DISK_CACHE_AS_PERCENT / 100; } catch (IllegalArgumentException ignored) { } // Bound inside min/max size for disk cache. return Math.max(Math.min(size, MAX_DISK_CACHE_SIZE), MIN_DISK_CACHE_SIZE); }
From source file:Main.java
public static String getSystemAlbumDir() { File file = new File(getSdCardAbsolutePath() + "/DCIM/Camera"); if (!file.exists()) file.mkdirs();//from w w w .j a v a 2 s .c om return file.getAbsolutePath(); }
From source file:Main.java
public static String getSendDir(Context context) { File fileDir = context.getExternalFilesDir(null); String dir = null;/*from w w w .j a v a2 s . co m*/ if (fileDir != null) { dir = fileDir.getAbsolutePath(); } else { dir = context.getFilesDir().getAbsolutePath(); } dir += "/mtc/bgimage/"; fileDir = new File(dir); fileDir.mkdirs(); return dir; }
From source file:Main.java
public static void installApk(Context context, File file) { if (context != null && isFileExists(file)) { Uri uri = Uri.fromFile(new File(file.getAbsolutePath())); Intent installIntent = new Intent(); installIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); installIntent.setAction(Intent.ACTION_VIEW); String type = "application/vnd.android.package-archive"; installIntent.putExtra("loadapk", "loadapk"); installIntent.setDataAndType(uri, type); context.startActivity(installIntent); }//from w ww . j a va 2 s. co m }
From source file:Main.java
static long calculateApiDiskCacheSize(File dir) { long size = MIN_DISK_API_CACHE_SIZE; try {// w w w .j a v a2 s.co m StatFs statFs = new StatFs(dir.getAbsolutePath()); long available; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { available = statFs.getBlockCountLong() * statFs.getBlockSizeLong(); } else { available = ((long) statFs.getBlockCount()) * statFs.getBlockSize(); } // Target 2% of the total space. size = available / 50; } catch (IllegalArgumentException ignored) { } // Bound inside min/max size for disk cache. return Math.max(Math.min(size, MAX_DISK_API_CACHE_SIZE), MIN_DISK_API_CACHE_SIZE); }
From source file:Main.java
public static void startRecord() { if (!haveStarted) { haveStarted = true;/*from ww w . j a va 2 s . c om*/ mRecorder = new MediaRecorder(); mRecorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL); mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); File pp = new File(path); if (!pp.isDirectory() && !pp.exists()) { pp.mkdir(); } currentFilePath = path + new SimpleDateFormat("yyyyMMddHHmmss").format(System.currentTimeMillis()) + ".mp3"; File saveFilePath = new File(currentFilePath); mRecorder.setOutputFile(saveFilePath.getAbsolutePath()); mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); try { mRecorder.prepare(); } catch (IOException e) { Log.e(TAG, "prepare() failed"); } mRecorder.start(); } }
From source file:ark.util.FileUtil.java
public static JSONObject readJSONFile(File file) { return readJSONFile(file.getAbsolutePath()); }
From source file:avantssar.aslanpp.testing.HTMLHelper.java
public static String removePrefix(File root, File f) { String fNorm = FilenameUtils.normalize(f.getAbsolutePath()); String relativePath = fNorm;/*from w w w . ja va2 s . c om*/ if (root.isDirectory()) { String rootNorm = FilenameUtils.normalizeNoEndSeparator(root.getAbsolutePath()) + File.separator; if (relativePath.startsWith(rootNorm)) { relativePath = relativePath.substring(rootNorm.length()); } } return relativePath; }
From source file:Main.java
private static void throwExceptionForInvalidXmlFile(Throwable rootCause, File deploymentDescriptorFile) { throw new IllegalArgumentException( "The provided descriptor is not a valid XML file:" + deploymentDescriptorFile.getAbsolutePath(), rootCause);// w ww . j a v a 2 s . co m }