我有一个类(从互联网上下载)以这种方式读取文件的值(并在分割文件后):
NSArray* array = [fileContents componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
其中fileContents是我的完整路径。
以哪种方式我必须写我的字符串? 我正在尝试这个:
NSString *data = [NSString stringWithFormat:@"%@,%@""\n", latitudine.text, longitudine.text];
NSFileHandle *handle;
handle = [NSFileHandle fileHandleForWritingAtPath: [self dataFilePath] ];
[handle truncateFileAtOffset:[handle seekToEndOfFile]];
[handle writeData:[data dataUsingEncoding:NSUTF8StringEncoding]];
我疯了:D
有什么帮助吗?!?
答案 0 :(得分:0)
NSString *data = somethingblablabla ;
NSData *myData = [data dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSFileHandle *writeData = [NSFileHandle fileHandleForWritingAtPath:[self dataPath]];
[writeData truncateFileAtOffset:[writeData seekToEndOfFile]];
[writeData writeData:myData];