//写文件
// return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
NSMutableString *mystring = [[NSMutableString alloc] init];
NSError *err;
for(int i = 0; i < 10; i++){
[mystring appendString:@"This is for reading file .\n"];
[mystring writeToFile:@"/tmpa/myfile2.txt"
atomically:YES
encoding:NSUTF8StringEncoding
error:&err];
}
NSLog(@"Yes, the file is writen done with %@", [err localizedDescription]);
//读文件
NSError *readerr;
NSString *str = [[NSString alloc] initWithContentsOfFile:@"/tmp/myfile2.txt"
encoding:NSUTF8StringEncoding
error:&readerr];
if(!str){
NSLog(@"Read file with Error:%@", [readerr localizedDescription]);
}else{
NSLog(@"The file has the contents as below: %@", str);
}