The file “city.txt” couldn’t be opened using text encoding Unicode (UTF-8)
来源:互联网 发布:美国折扣网站 知乎 编辑:程序博客网 时间:2024/05/19 22:51
txt文件 转化为plist文件
NSString *txtPath = [[NSBundlemainBundle] pathForResource:fileNameofType:@"txt"];
NSLog(@"_____%@",txtPath);
NSError *err;
NSString *txtContent = [NSStringstringWithContentsOfFile:txtPath encoding:NSUTF8StringEncoding error:&err];
NSLog(@"%@__----____-",err);
The file “city.txt” couldn’t be opened using text encoding Unicode (UTF-8)这种一般是格式错误引起的,无法读取。我的txt 是中文文件出现乱码,所以用GBK中文编码。需要确认文件编码方式
unsigned long encode =CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
NSData *responseData = [NSDatadataWithContentsOfFile:fileName ];
NSString *mTxt = [[NSStringalloc] initWithData:responseDataencoding:encode];
NSArray *txtArry = [mTxtcomponentsSeparatedByString:@"\r\n"];
for (NSString *questionin txtArry) {
NSLog(@"%@_----___",question);
NSRange range = [questionrangeOfString:@" "];
if (range.location !=NSNotFound) {
NSString *answer = [questionsubstringToIndex:range.location];
NSString *imageName = [questionsubstringFromIndex:range.location+1];
imageName = [imageName stringByTrimmingCharactersInSet:[NSCharacterSetwhitespaceCharacterSet]];
NSDictionary *dic = [NSDictionarydictionaryWithObjectsAndKeys:answer,imageName,nil];
[plistArry addObject:dic];
NSLog(@"%lu....%lu,,,,",(unsignedlong)range.location,(unsignedlong)range.length);
}else{
NSLog(@"%lu....%lu,,,,----",(unsignedlong)range.location,(unsignedlong)range.length);
}
}
NSLog(@"%@____%lu",plistArry,(unsignedlong)plistArry.count);
//写到plist文件中
NSArray *stringPath =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *docDirectory = [stringPathobjectAtIndex:0];
NSString *path = [docDirectorystringByAppendingPathComponent:@"brand.plist"];
NSLog(@"%@",path);
[plistArry writeToFile:pathatomically:YES
- The file “city.txt” couldn’t be opened using text encoding Unicode (UTF-8)
- xcode 出现 The file couldn’t be opened.
- Xcode6:The file couldn’t be opened because you don’t have permission to view it
- Xcode6:The file couldn’t be opened because you don’t have permission to view it
- Xcode6:The file couldn’t be opened because you don’t have permission to view it
- The file “***” couldn’t be opened because you don’t have permission to view it
- 解决方案:The file * couldn't be opened because you don't have permission to view it
- Xcode6:The file couldn’t be opened because you don’t have permission to view it
- the file couldn't be opened because you don't have permission to view it
- the file couldn't be opened because you don't have permission to view it 解决办法
- The file “xxx” couldn’t be opened because you don’t have permission to view it.
- The file “XXX” couldn’t be opened because you don’t have permission to view it.
- [ios]the file couldn't be opened because you don't have permission to view it
- The file couldn't be opened because you don't have permission to view it.解决办法
- Xcode6:The file couldn’t be opened because you don’t have permission to view it
- The file “XXX” couldn’t be opened because you don’t have permission to view it.
- The file “” couldn’t be opened because you don’t have permission to view it.
- the file couldn't be opened because you don't have permission to view it
- ExtJS学习之TreePanel
- linux下重命名文件或文件夹
- 如何实现一个循环显示超长图片的控件
- Windows上面Apache的环境变量
- 【打CF,学算法——四星级】CodeForces 514D R2D2 and Droid Army (RMQ+二分)
- The file “city.txt” couldn’t be opened using text encoding Unicode (UTF-8)
- spring-jar包介绍
- Ubuntu Core介绍及其使用
- Mybatis 动态切换数据库
- AFN HTTPS的访问实现原理 安全考虑以及网络监听
- Junit中的Assert方法
- 有趣的Node
- 用java怎么创建一副扑克牌
- hdu 1013