我想在文件“file.txt”中写入一个字符串:我的项目(针对Iphone)中的该文件位于资源内部;我尝试在此文件中写入一个字符串,但它不起作用,我显示了我的代码。
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"file.txt"];
NSError *error;
[outputString writeToFile:filePath atomically:YES encoding:NSUTF8StringEncoding error:&error];
我想使用模拟器 xcode 写入此文件,而不是使用设备
最佳答案
我不确定您是否能够在包中编写,但您可以像代码一样在文档目录中编写。你为什么不试试这个呢?
使用相同的代码,您将在以下位置找到您的文件:
/Users/YOURUSER/Library/Application Support/iPhone Simulator/IOSVERSION/Applications/APPID/Documents/file.txt
关于iphone - Xcode:iPhone模拟器的目录文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5593064/