示例代码:
-(void) writeData:(NSString*) data
{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *fileName = [[self businessId] stringByAppendingString:@".txt"];
NSString *filePath = [[YLSGlobalUtils getBackupDirPath] stringByAppendingPathComponent:fileName];
if(![fileManager fileExistsAtPath:filePath]){
[fileManager createFileAtPath:filePath contents:nil attributes:nil];
}
[data writeToFile:filePath atomically:YES encoding:NSUTF8StringEncoding error:nil];
}
创建文件,然后写入。特别简单没啥说的
另外NSData也有一个同名方法,应该比较适合大数据写入