开发者

iphone sdk see size of local file (one created by application)

开发者 https://www.devze.com 2022-12-11 00:18 出处:网络
Is there anyway I can look at the size of a file the application creates in bytes then store that number to use later?O开发者_运维问答R is there any way I can tell if an object in an NSArray is empty,

Is there anyway I can look at the size of a file the application creates in bytes then store that number to use later? O开发者_运维问答R is there any way I can tell if an object in an NSArray is empty, I've tried everything, but it just doesn't work!


Use NSFileManager class' method

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

The size key in the returned dictionary is defined as

NSString * const NSFileSize;

So for an example

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

if (!error) {
    NSNumber *size = [attributes objectForKey:NSFileSize];
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号