IOS读取本地文件内容

来源:互联网 发布:mp4淘宝网 编辑:程序博客网 时间:2024/05/17 12:56
1.
  NSError *error=nil;
 
// 通过指定的路径读取文本内容
 NSString *str = [NSString stringWithContentsOfFile:[[NSBundle mainBundlepathForResource:@"1"ofType:@"txt"] encoding:NSUTF8StringEncoding error:&error];
 
NSLog(@"srt=%@",str);

2.
// 指定路径读

 NSString *filePath=[[NSBundle mainBundlepathForResource:@"1"ofType:@"txt"];

NSString *str=[[NSString allocinitWithContentsOfFile:filePath];

NSLog(@"%@",str);

0 0