写文件操作
// 保存图像时,需要使用NSData进行中转,NSData中间可以存储任意格式的二进制数据
    // 1. 将UIImage转换成NSData
    NSData *imageData = UIImagePNGRepresentation(image);
    // 2. 建立保存文件的路径
    NSArray *documents = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    
    NSLog(@"%@",documents[0]);
    NSString *path = [documents[0] stringByAppendingPathComponent:@"image.png"];
    // 3. 将NSData写入文件
    [imageData writeToFile:path atomically:YES];
    
  NSString *imagePath = [[NSBundle mainBundle] pathForResource:@”
image” ofType:@”png”];
  UIImage *appleImage = [[UIImage alloc] initWithContentsOfFile:imagePath];
// 4. 将NSString写入文件
    NSString *string = @"老虎爱油!!!";
    NSString *strPath = [documents[0] stringByAppendingPathComponent:@"123.txt"];
    [string writeToFile:strPath atomically:YES encoding:NSUTF8StringEncoding error:nil];
    
    // 5. 将info写入Documents保存
    NSString *infoPath = [documents[0] stringByAppendingPathComponent:@"info.plist"];
    [info writeToFile:infoPath atomically:YES];
    NSLog(@"info写入成功吗?");

 

posted on 2015-07-22 16:40  pTrack  阅读(161)  评论(0)    收藏  举报