List of usage examples for java.io File getUsableSpace
public long getUsableSpace()
From source file:Main.java
public static void main(String[] args) throws Exception { // create new files File f = new File("c:/"); System.out.print(f.getUsableSpace()); }
From source file:Main.java
public static long getUsableSpace(File path) { return path.getUsableSpace(); }
From source file:Main.java
/** * Check how much usable space is available at a given path. * // w ww . java 2 s . c om * @param path * The path to check * @return The space available in bytes */ public static long getUsableSpace(File path) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { return path.getUsableSpace(); } final StatFs stats = new StatFs(path.getPath()); return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks(); }
From source file:Main.java
/** * Check how much usable space is available at a given path. * * @param path The path to check// w w w . j av a2 s . c o m * * @return The space available in bytes */ public static long getUsableSpace(File path) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { return path.getUsableSpace(); } final StatFs stats = new StatFs(path.getPath()); return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks(); }
From source file:Main.java
/** * Check how much usable space is available at a given path. * * @param path The path to check/* ww w. ja v a 2 s. co m*/ * @return The space available in bytes */ @SuppressLint("NewApi") public static long getUsableSpace(File path) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { return path.getUsableSpace(); } final StatFs stats = new StatFs(path.getPath()); return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks(); }
From source file:Main.java
@SuppressLint("NewApi") public static final long getUsableSpace(String accountName) { File savePath = Environment.getExternalStorageDirectory(); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.GINGERBREAD) { return savePath.getUsableSpace(); } else {//www . j a v a 2 s .c o m StatFs stats = new StatFs(savePath.getAbsolutePath()); return stats.getAvailableBlocks() * stats.getBlockSize(); } }
From source file:org.proninyaroslav.libretorrent.core.utils.FileIOUtils.java
public static long getFreeSpace(String path) { long availableBytes = -1L; try {/*from w ww . j a v a 2s.c om*/ File file = new File(path); availableBytes = file.getUsableSpace(); } catch (Exception e) { // this provides invalid space on some devices try { StatFs stat = new StatFs(path); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { availableBytes = stat.getAvailableBytes(); } else { availableBytes = stat.getAvailableBlocks() * stat.getBlockSize(); } } catch (Exception ee) { /* Ignore */ } } return availableBytes; }
From source file:org.jenkinsci.plugins.periodicbackup.Util.java
/** * * This test if a given file is a valid serialized BackupObject file * * @param backupObjectFile File to test/*from ww w .j av a2s . co m*/ * @return true if valid, false otherwise * @throws IOException If an IO problem occurs */ public static boolean isValidBackupObjectFile(File backupObjectFile) throws IOException { if (!backupObjectFile.exists() || !(backupObjectFile.getUsableSpace() > 0)) return false; else { String fileAsString = Files.toString(backupObjectFile, Charsets.UTF_8); return fileAsString.contains("fileManager class=\"org.jenkinsci.plugins.periodicbackup") && fileAsString.contains("storage class=\"org.jenkinsci.plugins.periodicbackup") && fileAsString.contains("location class=\"org.jenkinsci.plugins.periodicbackup"); } }
From source file:com.android.volley.misc.Utils.java
/** * Check how much usable space is available at a given path. * /* w ww. j av a2 s .c o m*/ * @param path * The path to check * @return The space available in bytes */ @SuppressWarnings("deprecation") @TargetApi(9) public static long getUsableSpace(File path) { if (Utils.hasGingerbread()) { return path.getUsableSpace(); } final StatFs stats = new StatFs(path.getPath()); return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks(); }
From source file:com.sqkj.engine.image.ImageCache.java
/** * Check how much usable space is available at a given path. * * @param path The path to check/*ww w. j a v a2s . c o m*/ * @return The space available in bytes */ public static long getUsableSpace(File path) { if (SdkUtils.hasGingerbread()) { return path.getUsableSpace(); } final StatFs stats = new StatFs(path.getPath()); return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks(); }