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

Mat*_* S. 3 iphone cocoa file nsdata nsarray

无论如何,我可以查看应用程序以字节为单位创建的文件的大小,然后存储该号码以便以后使用?或者有什么方法我可以判断一个NSArray中的对象是否为空,我已经尝试了一切,但它只是不起作用!

ndu*_*sis 22

使用NSFileManager类的方法

- (NSDictionary *)attributesOfItemAtPath:(NSString *)path error:(NSError **)error
Run Code Online (Sandbox Code Playgroud)

返回字典中的大小键定义为

NSString * const NSFileSize;
Run Code Online (Sandbox Code Playgroud)

举个例子

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

if (!error) {
    NSNumber *size = [attributes objectForKey:NSFileSize];
}
Run Code Online (Sandbox Code Playgroud)