c语言 实现
include “sys/stat.h”
- (long long) fileSizeAtPath:(NSString*) filePath{
struct stat st;
if(lstat([filePath cStringUsingEncoding:NSUTF8StringEncoding], &st) == 0){
return st.st_size;
}
return 0;
}
objective-c 语言实现
-(long long) fileSizeAtPath:(NSString*) filePath{
NSFileManager* manager = [NSFileManager defaultManager];
if ([manager fileExistsAtPath:filePath]){
return [[manager attributesOfItemAtPath:filePath error:nil] fileSize];
}
return 0;
}
转载自:http://blog.sina.com.cn/s/blog_5fb39f910101di98.html