Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

bboyjayz

macrumors member
Original poster
Mar 20, 2009
55
0
hi,
i've a problem, i try to save strings i read since a fichier.txt file on the web, and save it into my iPhone, it's work fine, but when i call my saved file since another class, it's seems to be empty, here is my source code to save my file:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:mad:"random.txt"];

if([string writeToFile:filePath atomically:YES encoding:NSUTF16BigEndianStringEncoding error:NULL]){
NSLog(@"OK");
}
NSLog([NSString stringWithContentsOfFile:filePath encoding:NSUTF16BigEndianStringEncoding error:NULL]);
//this NLog work fine, i see my saved data.



And i want to read it since another class, here is my code:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

//NSString *path = [[NSBundle mainBundle] pathForResource:aPath ofType:mad:"txt"];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:mad:"random.txt"];

NSString *string = [NSString stringWithContentsOfFile:filePath encoding:NSUTF16BigEndianStringEncoding error:NULL];
NSLog(string);
NSLog(@"Do am i here?");

Even the "Do am i here" does'nt work ... when i look the Console, i can see that to save my file, it switch task...i don't know how to do...please help...
 
First off, I'd suggest making a function/method for getting the path of that file, so that you don't have duplicate code and potentially introducing a bug from a simple typo.

Second, does NSFileManager's fileExistsAtPath: method show that it's there?
 
So this morning (I'm french and in France.. ) i've seen your answer and that show me how to test the filepath....so thank you for your answer 'cause know it works fine XD the error wasn't caused by the code i past... :(

Thank you very much...

PS: i love macrumors <3
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.