[英]Read and write file in iPhone
How to make file read/write operation on iPhone?which is the path i need to specify to save the file? 如何在iPhone上进行文件读/写操作?这是我需要指定保存文件的路径? how can i get the current working directory in iPhone?
我怎样才能获得iPhone当前的工作目录?
Thank You 谢谢
Write to a file: 写入文件:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
// the path to write file
NSString *myFile = [documentsDirectory stringByAppendingPathComponent:@"myFile"];
[data writeToFile:myFile atomically:YES];
Read a file: 阅读文件:
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"MyFile" ofType:@"txt"];
NSData *myData = [NSData dataWithContentsOfFile:filePath];
if (myData) {
// do something useful
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.