代码
#include <sys/param.h>
#include <sys/mount.h>
long long freeSpace() {
struct statfs buf;
long long freespace = -1;
if(statfs("/", &buf) >= 0){
freespace = (long long)buf.f_bsize * buf.f_bfree;
}
return freespace;
}
+(float)getTotalDiskSpaceInBytes {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
struct statfs tStats;
statfs([[paths lastObject] cString], &tStats);
float totalSpace = (float)(tStats.f_blocks * tStats.f_bsize);
return totalSpace;
}
//以上代码,需要的.h里进行声明,应用如下:
NSLog(@"total disk= %.2f GB", [Utilitys getTotalDiskSpaceInBytes] / (1024.0 * 1024.0 * 1024));
NSLog(@"free disk= %.2f GB", freeSpace() / (1024.0 * 1024.0 * 1024));
#include <sys/mount.h>
long long freeSpace() {
struct statfs buf;
long long freespace = -1;
if(statfs("/", &buf) >= 0){
freespace = (long long)buf.f_bsize * buf.f_bfree;
}
return freespace;
}
+(float)getTotalDiskSpaceInBytes {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
struct statfs tStats;
statfs([[paths lastObject] cString], &tStats);
float totalSpace = (float)(tStats.f_blocks * tStats.f_bsize);
return totalSpace;
}
//以上代码,需要的.h里进行声明,应用如下:
NSLog(@"total disk= %.2f GB", [Utilitys getTotalDiskSpaceInBytes] / (1024.0 * 1024.0 * 1024));
NSLog(@"free disk= %.2f GB", freeSpace() / (1024.0 * 1024.0 * 1024));
id 博主 = [[KILONET.CNBLOGS.COM alloc] initWithValue:@"天堂向右,我依然向左"
网名:@"老舟"
兴趣:@"影音,阅读"
动态:@"系统架构设计,Android通信模块开发"
网址:@"http://kilonet.cnblogs.com"
签名:@"--------------------------------------------------
Stay Hungry , Stay Foolish
求 知 若 渴,处 事 若 愚
--------------------------------------------------"
]; // Never Release