文件管理

1. 写入文件

 1 - (void)writelogToDocumentFolder
 2 {
 3     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
 4     NSString *documentDirectory = [paths objectAtIndex:0];
 5     NSString *fileName = [NSString stringWithFormat:@"pandatv_file.log"];
 6     NSString *logFilePath = [documentDirectory stringByAppendingPathComponent:fileName];
 7     // 先删除已经存在的文件
 8     NSFileManager *defaultManager = [NSFileManager defaultManager];
 9     [defaultManager removeItemAtPath:logFilePath error:nil];
10 
11     // 将log输入到文件
12     freopen([logFilePath cStringUsingEncoding:NSASCIIStringEncoding], "a+", stdout);
13     freopen([logFilePath cStringUsingEncoding:NSASCIIStringEncoding], "a+", stderr);
14 }

 

posted on 2018-06-05 16:03  活最好的自己  阅读(104)  评论(0编辑  收藏  举报

导航