本文介绍了iPhone writeToFile不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我编写了一个将txt文件保存到设备中的应用程序.在模拟器上进行测试时,我可以读写文件.在设备上进行测试后,读取工作正常,但未在该文本文件上写入任何内容.我已经搜索了解决方案,但似乎它在正确访问方面存在问题.任何人都可以建议我如何进行这项工作?
I have written one application that save txt file into device. When I test on simulator, I am able to read and write file. After I test on device, read is working fine but it doesn't write anything on that text file. I have searched for the solution but it seems like it has problem with right access. Anyone can suggest me how to make this work?
推荐答案
您使用什么路径将文件保存到?
What path are you using to save the file to?
我正在使用
- (NSString *)dataFilePath{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
return [documentsDirectory stringByAppendingPathComponent:@"myFileNameHere.txt"];
}
,然后将[self dataFilePath];
作为路径传递到writeToFile方法
and then pass [self dataFilePath];
into the writeToFile method as the path
这篇关于iPhone writeToFile不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!