Hi all,
If you want to save anything in text file or any kind of file than you can follow this code. This code will save text to textfile in your application directory.You can retrieve text from save file later on .
NSError *error;
NSString *stringToWrite = @"1\n2\n3\n4";
NSString *filePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject] stringByAppendingPathComponent:@"myfile.txt"];
[stringToWrite writeToFile:filePath atomically:YES encoding:NSUTF8StringEncoding error:&error];
Now file is saved as myfile.txt in your application directory and if you want to reopen that file than you can reopen your file with this code.
NSString *str = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:&error];
NSLog(@"%@", str);
0 Comment(s)