Example usage for android.os StatFs StatFs

List of usage examples for android.os StatFs StatFs

Introduction

In this page you can find the example usage for android.os StatFs StatFs.

Prototype

public StatFs(String path) 

Source Link

Document

Construct a new StatFs for looking at the stats of the filesystem at path .

Usage

From source file:Main.java

public static String getSavePath() {
    String savePath = null;//ww w  .j av a 2s.c  o  m
    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
        savePath = Environment.getExternalStorageDirectory().getAbsolutePath();
    } else {
        File[] files = new File("/mnt/").listFiles();
        if (files.length > 0) {
            String filePath = null;
            for (int p = 0; p < files.length; p++) {
                if (files[p].isDirectory()) {
                    if (files[p].getPath().indexOf("sdcard") >= 0) {
                        StatFs st = new StatFs(files[p].getPath());
                        int blocksize = st.getBlockSize();
                        int blockcount = st.getBlockCount();
                        if ((blocksize * blockcount) > 0) {
                            filePath = files[p].getPath();
                        }
                    }

                }
            }
            if (filePath != null) {
                savePath = filePath;
            } else {
                savePath = null;
            }
        }
    }
    return savePath;
}

From source file:Main.java

public static long getUsableSpace(File path) {
    final StatFs stats = new StatFs(Environment.getExternalStorageDirectory().getPath());
    return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks();
}

From source file:Main.java

public static long getAvailableSize(String path) {
    try {//  w  w w  .jav a  2  s  .c  o  m
        File base = new File(path);
        StatFs stat = new StatFs(base.getPath());
        long nAvailableCount = stat.getBlockSize() * ((long) stat.getAvailableBlocks());
        return nAvailableCount;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return 0;
}

From source file:Main.java

/**
 * @return the number of bytes available on the filesystem rooted at the given File
 *//* w w  w. j  av  a2 s .c  o  m*/
public static long getAvailableBytes(File root) {
    StatFs stat = new StatFs(root.getPath());
    long availableBlocks = (long) stat.getAvailableBlocks() - 4;
    return stat.getBlockSize() * availableBlocks;
}

From source file:Main.java

public static long getAvailableInnerSpace() {
    File path = Environment.getDataDirectory();
    StatFs stat = new StatFs(path.getPath());
    long blockSize = stat.getBlockSize();
    long availableBlocks = stat.getAvailableBlocks();
    long realSize = blockSize * availableBlocks;
    return realSize;
}

From source file:Main.java

/**
 * @return the number of bytes available on the filesystem rooted at the
 *         given File//from w  w w  .  j  a  v a2  s. com
 */
public static long getAvailableBytes(File root) {
    StatFs stat = new StatFs(root.getPath());
    // put a bit of margin (in case creating the file grows the system by a
    // few blocks)
    long availableBlocks = (long) stat.getAvailableBlocks() - 4;
    return stat.getBlockSize() * availableBlocks;
}

From source file:Main.java

public static long getAvailaleSDCardSize() {
    File path = Environment.getExternalStorageDirectory();
    StatFs stat = new StatFs(path.getPath());
    long blockSize = stat.getBlockSize();
    long availableBlocks = stat.getAvailableBlocks();

    long asize = availableBlocks * blockSize;
    LOG("getAvailaleSDCardSize asize: " + asize);
    return asize;
}

From source file:Main.java

@SuppressWarnings("unused")
public static long getTotalBytes(File dir) {
    if (!dir.exists() && !dir.mkdirs()) {
        return 0;
    }// ww  w .j  av  a2 s  .  c o  m
    StatFs dirStatFs = new StatFs(dir.getPath());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        return dirStatFs.getTotalBytes();
    } else {
        //noinspection deprecation
        return (long) dirStatFs.getBlockCount() * dirStatFs.getBlockSize();
    }
}

From source file:Main.java

@SuppressWarnings("WeakerAccess")
public static long getAvailableBytes(File dir) {
    if (!dir.exists() && !dir.mkdirs()) {
        return 0;
    }/*from   w w w  . jav  a  2  s .  co m*/
    StatFs dirStatFs = new StatFs(dir.getPath());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        return dirStatFs.getAvailableBytes();
    } else {
        //noinspection deprecation
        return (long) dirStatFs.getAvailableBlocks() * dirStatFs.getBlockSize();
    }
}

From source file:Main.java

public static long getAvailableExternalSpace() {
    File path = new File(Environment.getExternalStorageDirectory().getAbsolutePath());
    StatFs stat = new StatFs(path.getPath());
    long blockSize = stat.getBlockSize();
    long availableBlocks = stat.getAvailableBlocks();
    return availableBlocks * blockSize;
}