你也可以做到以下几点:
// create an NSURL object that holds the path of the file you want to read
NSURL *fileURL = [NSURL fileURLWithPath:@"/Users/yourname/weekdays.txt"];
//Create an NSMutaable string object and use the stringWithContentsOfURL: encoding: error: method to hold whatever might be you have in the text file.
//Just pass the NSURL object you created in the previous step to as an argument like so
NSMutableString *text = [NSMutableString stringWithContentsOfURL:fileURL encoding:NSUTF8StringEncoding error:nil];
NSLog(@"The content of the file is: %@", text);
就是这样。 NSLog实际上会输出你在文件中输入的内容,只是为了证明这一点。
是的,它的工作。谢谢你的帮助。 – likecatfood