-(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;
}
时间: 2024-10-09 21:56:29