- (void)showInfo
{
NSDirectoryEnumerator *fileEnumerator = [[NSFileManager defaultManager] enumeratorAtPath:diskCachePath];
int i = 0;
float total = 0.0f;
NSNumberFormatter *numberFormatter =[[NSNumberFormatter alloc] init];
[numberFormatter setPositiveFormat: @"#,##0.## bytes"];
for (NSString *fileName in fileEnumerator){
NSLog(@"filename %d : %@", i, fileName);
NSString *filePath = [diskCachePath stringByAppendingPathComponent:fileName];
NSDictionary *attrs = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil];
if (attrs) {
//获取文件的字节大小
NSNumber *fileSize = (NSNumber*)[attrs objectForKey: NSFileSize];
total = [fileSize floatValue] + total;
//格式化文件大小
NSString *A = [numberFormatter stringFromNumber: fileSize];
NSLog(@"filesize %d : %@", i, A);
}
++i;
}
NSLog(@"%f bytes (%f M) in cache", total, total / 1024.0 / 1024.0);
[numberFormatter release];
}
SDImageCache *cache = [SDImageCachesharedImageCache];
NSLog(@"cache 位置: %@", [cache getDiskCachePath]);
[cache clearDisk];
[cache clearMemory];

本文介绍了一个Objective-C方法,用于显示指定路径下所有文件的信息,并统计总大小。此外,还展示了如何使用SDImageCache清除内存和磁盘缓存。
852

被折叠的 条评论
为什么被折叠?



