0
我有一個存儲用戶數據的應用程序,如圖像和文本。我想顯示我的應用程序佔用了多少磁盤空間。這可能嗎?如何以編程方式獲取App使用的存儲狀態?
我有一個存儲用戶數據的應用程序,如圖像和文本。我想顯示我的應用程序佔用了多少磁盤空間。這可能嗎?如何以編程方式獲取App使用的存儲狀態?
我不知道所有三個,但我已經做了一些通過文件管理器來獲得,在目錄文件的大小,可能這會幫助你,這裏是代碼
[[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&isDir];
if (isDir) {
NSPipe *pipe = [NSPipe pipe];
NSTask *t = [[[NSTask alloc] init] autorelease];
[t setLaunchPath:@"/usr/bin/du"];
[t setArguments:[NSArray arrayWithObjects:@"-k", @"-d", @"0", path, nil]];
[t setStandardOutput:pipe];
[t setStandardError:[NSPipe pipe]];
[t launch];
[t waitUntilExit];
NSString *sizeString = [[[NSString alloc] initWithData:[[pipe fileHandleForReading] availableData] encoding:NSASCIIStringEncoding] autorelease];
sizeString = [[sizeString componentsSeparatedByString:@" "] objectAtIndex:0];
bytes = [sizeString longLongValue]*1024;
}
else {
bytes = [[[NSFileManager defaultManager] attributesOfItemAtPath:path error:nil] fileSize];
}
字節將返回大小
你在哪裏存儲你的數據?它在sqlite文件或NSDocumentsDirectory或使用NSFileManager – Charan 2012-04-11 08:29:25
使用所有三個。 – 2012-04-11 08:38:17