//File Path = app's documents folder
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
NSString *fileName =
[documentsDir stringByAppendingPathComponent:@"data2.txt"];
//File write
NSMutableArray *array = [[NSMutableArray alloc] init];
[array addObject:@"Text1"];
[array addObject:@"Text2"];
[array writeToFile:fileName atomically:YES];
//File read
if ([[NSFileManager defaultManager] fileExistsAtPath:fileName]){
NSArray *array = [[NSArray alloc] initWithContentsOfFile: fileName];
NSLog(@"%@",array);
}
//// Image File Save
- (IBAction)saveAction:(id)sender {
NSMutableArray *array = [[NSMutableArray alloc] init];
[array addObject:UIImagePNGRepresentation(self.imageView.image)];
[array writeToFile:self.fileName atomically:YES];
ALERT(@"FileSave", @"Image Saved.");
}
- (IBAction)loadAction:(id)sender {
if ([[NSFileManager defaultManager] fileExistsAtPath:fileName]){
NSArray *array = [[NSArray alloc] initWithContentsOfFile: fileName];
UIImage *image = [UIImage imageWithData:[array objectAtIndex:0]];
self.imageView.image = image;
}