开发者

how to get data from file.txt into an NSMutableArray

I have file.txt data file in my project which is in resource folder.

Now i need to fetch the data from the file and load it into NSMutableArray.

how to approach to 开发者_开发技巧it.


First of all you need to read the file. And the you need to separate the string in components.

    NSString *fileString = [NSString stringWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"test" ofType:@"txt"] 
                                                     encoding:NSUTF8StringEncoding 
                                                        error:nil];
    NSMutableArray *stringsArray = [NSMutableArray arrayWithArray:[fileString componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]];

    NSLog(@"Array:%@",[stringsArray description]);

Good luck.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜