码迷,mamicode.com
首页 > 移动开发 > 详细

IOS-写文件到本地

时间:2015-07-28 18:37:16      阅读:222      评论:0      收藏:0      [点我收藏+]

标签:

-(void)writeToFileWithString:(NSString*)string withFileName:(NSString*)fileName{
   //@"Map_Succ.txt"
    NSString* fileName1 = [self filePath:fileName];
    NSFileManager* fileManager = [NSFileManager defaultManager];
    NSString* str = nil;
    if ( [fileManager fileExistsAtPath:fileName1]) {

        NSData* data = [NSData dataWithContentsOfFile:fileName1];
        str =[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
        string = [NSString stringWithFormat:@"%@\n%@",str,string];

    }

    [fileManager createFileAtPath:fileName1 contents:[ string dataUsingEncoding:NSUTF8StringEncoding] attributes:nil];

}
- (NSString*)filePath:(NSString*)fileName {
    NSArray* myPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString* myDocPath = [myPaths objectAtIndex:0];
    NSString* filePath = [myDocPath stringByAppendingPathComponent:fileName];
    return filePath;
}

IOS-写文件到本地

标签:

原文地址:http://blog.csdn.net/u010742414/article/details/47108461

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!