中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

SD卡相關的Android輔助類

2018-07-20    來源:open-open

容器云強勢上線!快速搭建集群,上萬Linux鏡像隨意使用
    import java.io.File;  
      
    import android.os.Environment;  
    import android.os.StatFs;  
      
    //SD卡相關的輔助類  
    public class SDCardUtils  
    {  
        private SDCardUtils()  
        {  
            /* cannot be instantiated */  
            throw new UnsupportedOperationException("cannot be instantiated");  
        }  
      
        /** 
         * 判斷SDCard是否可用 
         *  
         * @return 
         */  
        public static boolean isSDCardEnable()  
        {  
            return Environment.getExternalStorageState().equals(  
                    Environment.MEDIA_MOUNTED);  
      
        }  
      
        /** 
         * 獲取SD卡路徑 
         *  
         * @return 
         */  
        public static String getSDCardPath()  
        {  
            return Environment.getExternalStorageDirectory().getAbsolutePath()  
                    + File.separator;  
        }  
      
        /** 
         * 獲取SD卡的剩余容量 單位byte 
         *  
         * @return 
         */  
        public static long getSDCardAllSize()  
        {  
            if (isSDCardEnable())  
            {  
                StatFs stat = new StatFs(getSDCardPath());  
                // 獲取空閑的數(shù)據(jù)塊的數(shù)量  
                long availableBlocks = (long) stat.getAvailableBlocks() - 4;  
                // 獲取單個數(shù)據(jù)塊的大。╞yte)  
                long freeBlocks = stat.getAvailableBlocks();  
                return freeBlocks * availableBlocks;  
            }  
            return 0;  
        }  
      
        /** 
         * 獲取指定路徑所在空間的剩余可用容量字節(jié)數(shù),單位byte 
         *  
         * @param filePath 
         * @return 容量字節(jié) SDCard可用空間,內(nèi)部存儲可用空間 
         */  
        public static long getFreeBytes(String filePath)  
        {  
            // 如果是sd卡的下的路徑,則獲取sd卡可用容量  
            if (filePath.startsWith(getSDCardPath()))  
            {  
                filePath = getSDCardPath();  
            } else  
            {// 如果是內(nèi)部存儲的路徑,則獲取內(nèi)存存儲的可用容量  
                filePath = Environment.getDataDirectory().getAbsolutePath();  
            }  
            StatFs stat = new StatFs(filePath);  
            long availableBlocks = (long) stat.getAvailableBlocks() - 4;  
            return stat.getBlockSize() * availableBlocks;  
        }  
      
        /** 
         * 獲取系統(tǒng)存儲路徑 
         *  
         * @return 
         */  
        public static String getRootDirectoryPath()  
        {  
            return Environment.getRootDirectory().getAbsolutePath();  
        }  
      
      
    }  

標簽: ssd

版權申明:本站文章部分自網(wǎng)絡,如有侵權,請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉載文章言論不代表本站觀點!
本站所提供的圖片等素材,版權歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇:Android獲取內(nèi)置和外置SD卡路徑

下一篇:PHP文件讀寫