Android tools ------) SD card-related auxiliary classes
Import java. io. file; import android. OS. environment; import android. OS. statFs; // SD card-related auxiliary class public class SDCardUtils {private SDCardUtils () {/* cannot be instantiated */throw new UnsupportedOperationException ("cannot be instantiated ");} /*** determine whether SDCard is available ** @ return */public static boolean isSDCardEnable () {return Environment. getExternalStorageState (). equals (Environment. MEDIA_MOUNTED);}/*** get SD card path ** @ return */public static String getSDCardPath () {return Environment. getExternalStorageDirectory (). getAbsolutePath () + File. separator;}/*** get the remaining capacity unit of the SD Card byte ** @ return */public static long getSDCardAllSize () {if (isSDCardEnable ()) {StatFs stat = new StatFs (getSDCardPath (); // obtain the number of idle data blocks long availableBlocks = (long) stat. getAvailableBlocks ()-4; // obtain the size of a single data block (byte) long freeBlocks = stat. getAvailableBlocks (); return freeBlocks * availableBlocks;} return 0;}/*** get the remaining available capacity bytes of the space in the specified path, unit byte ** @ param filePath * @ return capacity byte SDCard space, internal storage space */public static long getFreeBytes (String filePath) {// if the path is under the SD card, obtain the available capacity of the SD card if (filePath. startsWith (getSDCardPath () {filePath = getSDCardPath ();} else {// if it is an internal storage path, obtain the available memory storage capacity filePath = Environment. getDataDirectory (). getAbsolutePath ();} StatFs stat = new StatFs (filePath); long availableBlocks = (long) stat. getAvailableBlocks ()-4; return stat. getBlockSize () * availableBlocks;}/*** obtain the system storage path ** @ return */public static String getRootDirectoryPath () {return Environment. getRootDirectory (). getAbsolutePath ();}}