NSString * txtFilePath = [[NSBundle mainBundle] pathForResource:@" /cnuu.rtf" ofType:@" rtf"];
NSString *str5=[NSString stringWithContentsOfFile:txtFilePath encoding:NSUTF8StringEncoding error:nil];
NSLog(@"%@",str5);
答案 0 :(得分:1)
虽然你的问题不是真的可以理解,但我猜你应该改变@" /cnuu.rtf"到@" cnuu"由于ofType:参数已包含扩展名,因此您没有指定路径,因此您不需要斜杠。
答案 1 :(得分:0)
这是因为您正在阅读/cnuu.rtf.rtf
文件,而不是您需要阅读cnuu.rtf
您需要阅读
NSString *txtFilePath = [[NSBundle mainBundle] pathForResource: @"cnuu.rtf" ofType:nil];
或
NSString *txtFilePath = [[NSBundle mainBundle] pathForResource: @"cnuu" ofType: @"rtf"];
并通过
阅读内容NSString *content = [NSString stringWithContentsOfFile:txtFilePath encoding:NSUTF8StringEncoding error:nil];
NSLog(@"%@", content);