ios獲取文件內容

方法一:

//通過指定路徑讀取

NSError *error = nil;

NSString *filePath = [NSString stringWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"test" ofType:@"json"] encoding:NSUTF8StringEncoding error:&error];

NSLog(@"filePath%@",filePath);

 

方法二:

//指定路徑讀取
NSString *filePath=[[NSBundle mainBundle] pathForResource:@"test"ofType:@"json"];

NSString *str=[[NSString alloc] initWithContentsOfFile:filePath];

NSLog(@"%@",str);

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章