数据转换
NSData -->UIImage
[UIImage imageWithData:<#(NSData *)#>];
UIImage --> NSData
NSData * data = UIImagePNGRepresentation(_imageView.image);
NSData --> NSString
NSString * string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSString --> NSData
NSData * data = [@"aaa" dataUsingEncoding:NSUTF8StringEncoding];
汉字 转换成 电脑能是别的码
[@"甄嬛传" stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
//通过fileManager获取到指定路径下文件的所有属性,得到一个字典
NSDictionary *attDic = [[NSFileManager defaultManager] attributesOfItemAtPath:path error:nil];
文件写入写出常用函数
-(BOOL)writeToFile:(NSString *)path atomically:(BOOL)flag;
-(id)initWithContentsOfFile:(NSString *)path;
如果文件中内容少的用NSUserDefaults,多的也可用SOL或者XML。
获取文件创建时间和大小的代码
NSDictionary *fileAttributes = [[NSFileManager defaultManager] fileAttributesAtPath:path traverseLink:YES];
image png,jpg格式判断
image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
NSData *data;
if (UIImagePNGRepresentation(image) == nil) {
data = UIImageJPEGRepresentation(image, 1);
} else {
data = UIImagePNGRepresentation(image);
}