List of usage examples for java.io File getAbsolutePath
public String getAbsolutePath()
From source file:Main.java
public static void appendLog(String text) { Log.d("LOGFILE", text); SimpleDateFormat sTime = new SimpleDateFormat("dd/MMM/yyyy - hh:mm:ss"); String timeFormat = sTime.format(new Date()); File sdCard = Environment.getExternalStorageDirectory(); File dir = new File(sdCard.getAbsolutePath() + "/Cura/Logs/"); dir.mkdirs();//from w w w .j a v a 2s. c om File logFile = new File(dir, "Cura_Logs_DEBUG.txt"); if (!logFile.exists()) { try { logFile.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } try { BufferedWriter buf = new BufferedWriter(new FileWriter(logFile, true)); if (text.compareTo("wipe") == 0) logFile.delete(); else { buf.append("[" + timeFormat + "] - "); buf.append(text); buf.newLine(); buf.close(); } } catch (IOException e) { e.printStackTrace(); } }
From source file:com.google.mr4c.content.RelativeContentFactory.java
private static void checkRelated(File file, File ancestor) { if (!file.getAbsolutePath().startsWith(ancestor.getAbsolutePath())) { throw new IllegalStateException(String.format("[%s] is not a decendent of [%s]", file, ancestor)); }//from w ww .ja v a2 s .c o m }
From source file:Main.java
/** * obtain /sdcard/Android/data/[packagename]/files */// w w w . ja va 2 s . c om public static String getSdFilesDir(Context context) { //TODO: check permission? if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { File filesDir = context.getExternalFilesDir(null); if (filesDir != null) { return filesDir.getAbsolutePath(); } else { return ""; } } else { return ""; } }
From source file:Main.java
public static String dataRootDirectory(int extNum) { File sdcard = Environment.getExternalStorageDirectory(); if (!sdcard.exists()) { sdcard = new File("/sdcard"); }//from www . ja va2 s . c om if (sdcard.exists()) { File rd = new File(sdcard, "YaoTouWan"); if (extNum > 0) { rd = new File(rd.getAbsolutePath() + extNum); } if (!rd.exists()) { if (rd.mkdirs()) { return rd.getAbsolutePath(); } } else if (rd.isDirectory()) { return rd.getAbsolutePath(); } else { return dataRootDirectory(extNum + 1); } } else { // todo no /sdcard/ return null; } return sdcard.getAbsolutePath(); }
From source file:Main.java
public static File getFile(File curdir, String file) { return getFile(curdir.getAbsolutePath(), file); }
From source file:Main.java
private static String getSDDir(String key_dir) { StringBuilder sb = new StringBuilder(); String absolutePath = Environment.getExternalStorageDirectory().getAbsolutePath();// /mnt/sdcard sb.append(absolutePath);// ww w . j a v a 2 s . co m sb.append(File.separator).append(ROOT_DIR).append(File.separator).append(key_dir); String filePath = sb.toString(); File file = new File(filePath); if (!file.exists()) { if (file.mkdirs()) { return file.getAbsolutePath(); } else { return ""; } } return file.getAbsolutePath(); }
From source file:Main.java
public static boolean checkFilesIsNeedDelete(String path, long intervalTime) { File file = new File(path); if (file == null && !file.exists()) { return false; }/*from w ww. j a v a 2 s . c om*/ if (file.isFile()) { deleteFileByIntervalTime(file, intervalTime); } else { File[] fileList = file.listFiles(); for (int i = 0; i < fileList.length; i++) { File temp = fileList[i]; if (temp.isDirectory()) { checkFilesIsNeedDelete(temp.getAbsolutePath(), intervalTime); } else { deleteFileByIntervalTime(temp, intervalTime); } } } return true; }
From source file:Main.java
public static final String[] getFileNames(final File[] files) { String[] filePaths = new String[files.length]; int i = 0;// w ww .j a v a 2 s . c o m for (File f : files) { // System.out.println((i + 1) + ". " + f.getAbsolutePath()); filePaths[i++] = f.getAbsolutePath(); } return filePaths; }
From source file:Main.java
public static String imageToLocal(Bitmap bitmap, String name) { String path = null;/* w w w. jav a2s .c o m*/ try { if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) { return null; } String filePath = Environment.getExternalStorageDirectory().getPath() + "/cache/"; File file = new File(filePath, name); if (file.exists()) { path = file.getAbsolutePath(); return path; } else { file.getParentFile().mkdirs(); } file.createNewFile(); OutputStream outStream = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outStream); outStream.flush(); outStream.close(); if (!bitmap.isRecycled()) { bitmap.recycle(); } path = file.getAbsolutePath(); } catch (Exception e) { } return path; }
From source file:com.adguard.compiler.PackageUtils.java
public static File createCrx(String makeCrxSh, File file, File certificate) throws Exception { execute(makeCrxSh, file.getAbsolutePath(), certificate.getAbsolutePath()); File crxFile = new File(file, file.getName() + ".crx"); File destCrxFile = new File(file.getParentFile(), crxFile.getName()); FileUtils.deleteQuietly(destCrxFile); FileUtils.moveFile(crxFile, destCrxFile); return destCrxFile; }