iphone - Troubles with NSString writeToFile -


I am using the following code to open the contents of a file and save it in another file. When it moves, the original file length is 793 but the saved file is 0. I have also tried to copy the file. Nothing seems to work.

Am I getting some permissions which I am missing on the directory of documents?

  NSError * error; NSString * Baspoint = [NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, Yes) objectAtIndex: 0]; NSString * nGram = [basepath stringbappingingpath company: @ "village with contacts"]; Nssting * ogram = [basepath stringbabypancypantcompanent: @ "/../ vText.app/model/lm/TAR9230/contacts.gram"]; NSString * gramString = [[NSString alloc] initWithContentsOfFile: OGram encoding: NSUTF8StringEncoding error: & amp; Error]; BOOL ok = [gramString writeToFile: Native Atom: No Encoding: NSUnicodeStringEncoding Error: & amp; Error]; If (! OK) NSLog (@ "Monday!"); NSLog (@ "% d", [Village Straighter Length]); Gramstreeting = [[NSSTING ELLOCK] Initvith contentofffile: NGRM encoding: NSUFF 8 string encoding error: & amp; Error]; NSLog (@ "% d", [Village Straighter Length]);  

This entire block is unnecessary. You only need:

  NSString * fp = [[NSBundle mainBundle] pathForResource: @ "Contact" type: @ "village"]; NSString * gramstring = [[NSString alloc] initWithContentsOfFile: FP encoding: NSUTF8 string encoding error: & amp; Error];  

You definitely do not want to try using a file directly in the app bundle using a hardblocked path because the file is not guaranteed to be in the same exact location in every build is.

You have a code that you want to use to use the same encoding stability to read while writing. You write from NSUnicodeStringEncoding , but you read with NSUTF8StringEncoding . They should overlap, but if you know the use of precise coding, why take the chance?


Comments