iphone app中读取本地txt,csv文件

- (void)readLocalData {
NSString *path = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"txt"];
NSString *contents = [[NSString alloc] initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
NSArray *contentsArray = [contents componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];

NSInteger idx;    
for (idx = 0; idx < contentsArray.count; idx++) {
NSString* currentContent = [contentsArray objectAtIndex:idx];
NSLog(@"%@",currentContent);
}
}

你可能感兴趣的:(iPhone,Path,csv,encoding)