Hey,
I'm trying to write to a file when i leave the view and when i load the view i want to read from that file.
On the simulator this works fine, but on the iPad it doesn't work at all. It doesn't seem to write to the file at all or read the file.
The file i have put in a folder called random, which i put into the Resources folder in XCode.
the code to read and write the files is very similar:
these lines are the same for both:
person is just a string with an underscore after it so you could end up with person being John_ so the file is John_name.txt
To read the file:
This just prints: myText
null)
To write the file:
I did try writing to the file using the NSString write to file method, but that didn't work either so i tried using the NSData method.
Anyone know what maybe the problem is.
I tried (because its in a sub folder)
neither worked
also as a long shot i tried these:
any help would be appreciated.
I'm trying to write to a file when i leave the view and when i load the view i want to read from that file.
On the simulator this works fine, but on the iPad it doesn't work at all. It doesn't seem to write to the file at all or read the file.
The file i have put in a folder called random, which i put into the Resources folder in XCode.
the code to read and write the files is very similar:
these lines are the same for both:
Code:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *file = [documentsDirectory stringByAppendingFormat:@"%@name", person];
person is just a string with an underscore after it so you could end up with person being John_ so the file is John_name.txt
To read the file:
Code:
NSString *myText = [NSString stringWithContentsOfFile:file encoding:NSUTF8StringEncoding error:nil];
NSLog(@"myText:%@", myText);
To write the file:
Code:
NSString *myText = [[NSString alloc] initWithFormat:@"%@", text];
[[myText dataUsingEncoding:NSUTF8StringEncoding] writeToFile:file atomically:YES];
I did try writing to the file using the NSString write to file method, but that didn't work either so i tried using the NSData method.
Anyone know what maybe the problem is.
I tried (because its in a sub folder)
Code:
NSString *file = [documentsDirectory stringByAppendingFormat:@"/folder/%@name", person];
NSString *file = [documentsDirectory stringByAppendingFormat:@"folder/%@name", person];
also as a long shot i tried these:
Code:
NSString *file = [documentsDirectory stringByAppendingFormat:@"/random/%@name.txt", person];
NSString *file = [documentsDirectory stringByAppendingFormat:@"random/%@name.txt", person];
NSString *file = [documentsDirectory stringByAppendingFormat:@"%@name.txt", person];
NSString *file = [documentsDirectory stringByAppendingFormat:@"/%@name.txt", person];