List of usage examples for java.io File getPath
public String getPath()
From source file:Main.java
/** * Returns the total number of bytes of external storage. * @return Bytes of external storage in total, or -1 if no SD card mounted. *///w ww . j av a2 s . c o m static public long getTotalExternalMemorySize() { if (isSDCardMounted()) { File path = Environment.getExternalStorageDirectory(); StatFs stat = new StatFs(path.getPath()); long blockSize = stat.getBlockSize(); long totalBlocks = stat.getBlockCount(); return totalBlocks * blockSize; } else { return -1; } }
From source file:Main.java
/** * Returns the number of bytes of external storage available. * @return Bytes of external storage available. *//* w w w . jav a2 s.c om*/ static public long getAvailableExternalMemorySize() { if (isSDCardMounted()) { File path = Environment.getExternalStorageDirectory(); StatFs stat = new StatFs(path.getPath()); long blockSize = stat.getBlockSize(); long availableBlocks = stat.getAvailableBlocks(); return availableBlocks * blockSize; } else { return -1; } }
From source file:Main.java
public static String saveFile(Context c, String filePath, String fileName, byte[] bytes) { String fileFullName = ""; FileOutputStream fos = null;//from ww w . j a v a 2s . com String dateFolder = new SimpleDateFormat("yyyyMMdd", Locale.CHINA).format(new Date()); try { String suffix = ""; if (filePath == null || filePath.trim().length() == 0) { filePath = Environment.getExternalStorageDirectory() + "/tuiji/" + dateFolder + "/"; } File file = new File(filePath); if (!file.exists()) { file.mkdirs(); } File fullFile = new File(filePath, fileName + suffix); fileFullName = fullFile.getPath(); fos = new FileOutputStream(new File(filePath, fileName + suffix)); fos.write(bytes); } catch (Exception e) { fileFullName = ""; } finally { if (fos != null) { try { fos.close(); } catch (IOException e) { fileFullName = ""; } } } return fileFullName; }
From source file:Main.java
public static boolean isValidXmlFile(final File file) { boolean result; try {// w w w.java2s .c o m final InputStream input = new FileInputStream(file.getPath()); final byte[] header = new byte[32]; input.read(header, 0, 32); String headerStr = new String(header, "ASCII"); String XML_REGEX = "^\\s*<(\\?|!(--)?)?\\s*\\w+.*"; result = headerStr.matches(XML_REGEX); try { input.close(); } catch (Exception e) { // ignore this exception } } catch (Exception e) { result = false; } return result; }
From source file:Main.java
public static boolean isBinaryPlist(final File source) { boolean result; try {/* ww w . j a va 2s . c om*/ final InputStream input = new FileInputStream(source.getPath()); final byte[] header = new byte[8]; input.read(header, 0, 8); result = true; result &= (header[0] == 0x62); // b result &= (header[1] == 0x70); // p result &= (header[2] == 0x6C); // l result &= (header[3] == 0x69); // i result &= (header[4] == 0x73); // s result &= (header[5] == 0x74); // t // The two next bytes are the version number input.close(); } catch (Exception e) { result = false; } return result; }
From source file:JOOQTest.java
@BeforeClass public static void setup() throws Exception { File webAppPath = new File("files"); micro = new Micro(webAppPath.getPath(), null, "../../lib"); Assert.assertNotNull(micro);/* ww w .ja v a2 s .c o m*/ SITE = micro.getSite(); Assert.assertNotNull(SITE); SITE.setMicroEnv(Globals.TEST); // we're overwriting the ExtensionManager bootstrap String extensionsFolder = System.getenv("EXTENSIONS_FOLDER"); Assert.assertNotNull("Must specify the extensions folder. Missing.", extensionsFolder); File extensionConfigFile = new File(extensionsFolder + EXTENSION_NAME + ".yml"); SITE.setExtensionsManager(new ExtensionsManager(SITE, new File[] { extensionConfigFile })); SITE.getExtensionsManager().require(EXTENSION_NAME); Assert.assertNotNull("Micro 'SITE' initialization failed", micro.getSite().getWebInfPath()); Assert.assertTrue("Micro is not pointing to the correct test web app", SITE.getWebInfPath().getAbsolutePath().contains("files/WEB-INF")); Assert.assertTrue("The Micro test web app is not properly defined", SITE.getWebInfPath().exists()); log.info("unit test setup, completed."); }
From source file:Main.java
/** * Format file name.//from w w w .j ava 2s .co m * If it's a directory, modify it like "/x/x/"; * else modify it like "/x/x". */ public static String getPathRuled(File file) { if (file == null) { return ""; } if (file.isDirectory()) { return file.getPath() + "/"; } return file.getPath(); }
From source file:Main.java
/** * Joins path elements using the systems path separator. e.g. "/tmp" and * "test.wav" combined together should yield /tmp/test.wav on UNIX. * //from ww w. j a va 2 s .co m * @param path * The path parts part. * @return Each element from path joined by the systems path separator. */ public static String combine(final String... path) { File file = new File(path[0]); for (int i = 1; i < path.length; i++) { file = new File(file, path[i]); } return file.getPath(); }
From source file:Main.java
/** * @return Total external memory//from w w w . ja v a2 s . co m */ public static int getTotalExternalMemorySize() { if (isExternalStorageAvailable()) { File path = Environment.getExternalStorageDirectory(); StatFs stat = new StatFs(path.getPath()); int blockSize = stat.getBlockSize(); int totalBlocks = stat.getBlockCount(); return totalBlocks * blockSize; } else { return 0; } }
From source file:fm.moe.android.util.JSONFileHelper.java
public static String getFilePath(final Context context, final String filename) { if (context == null || filename == null) return null; final File cache_dir; if (getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { cache_dir = new File(context.getExternalCacheDir(), JSON_CACHE_DIR); } else {//from w w w . j a v a 2 s .c o m cache_dir = new File(context.getCacheDir(), JSON_CACHE_DIR); } if (!cache_dir.exists()) { cache_dir.mkdirs(); } final File cache_file = new File(cache_dir, filename); return cache_file.getPath(); }