在iphone中读取文本文件

Idr*_*raf 2 iphone nsstring ios

我想读取放在服务器上的文本文件.例如我的文件放在这个链接上:http://mysite.com/files/objects.txt 如何将这个文件的内容读入NSString

Lin*_*ios 7

试试这个:

NSError* e;
NSString* str = [NSString stringWithContentsOfURL:@"http://mysite.com/files/objects.txt" encoding:NSASCIIEncoding error:&e]
if(e != nil) {
  //There was an error
}
//Everything good
Run Code Online (Sandbox Code Playgroud)