1)从文件读取字符串:initWithContentsOfFile方法
- NSString *path = @"string.txt";
- NSString *astring = [[NSString alloc] initWithContentsOfFile:path];
- NSLog(@"astring:%@",astring);
- [astring release]; //astring=nil;
2)写字符串到文件:writeToFile方法
- NSString *astring = [[NSString alloc] initWithString:@"Hello!"];
- NSLog(@"astring:%@",astring);
- NSString *path = @"string.txt";
- [astring writeToFile: path atomically: YES];
- [astring release]; //astring=nil;