Android examples for android.os:Disk
Retrieve the free size of a disk.
import android.os.StatFs; public class Main { /**/* w w w .j a v a 2 s . c o m*/ * Retrieve the free size of a disk. * * @param diskPath * the path of the disk. * @return the size of the disk in bytes. */ public static long getDiskFreeSize(final String diskPath) { try { final StatFs stat = new StatFs(diskPath); final long blockSize = stat.getBlockSize(); final long freeBlocks = stat.getAvailableBlocks(); final long totalSize = blockSize * freeBlocks; return totalSize; } catch (final Throwable e) { return 0; } } }