iphone sdk 查看本地文件的大小(由应用程序创建的文件)

问题描述 投票:0回答:1

如何查看应用程序创建的文件的大小(以字节为单位)?

ios file cocoa nsdata
1个回答
22
投票

使用 NSFileManager 类的方法

- (NSDictionary *)attributesOfItemAtPath:(NSString *)path error:(NSError **)error

返回的字典中的size键定义为

NSString * const NSFileSize;

举个例子

NSError *error = nil;
NSDictionary *attributes = [[NSFileManager defaultManager] 
    attributesOfItemAtPath:@"/path/to/file" error:&error];

if (!error) {
    NSNumber *size = [attributes objectForKey:NSFileSize];
}
© www.soinside.com 2019 - 2024. All rights reserved.