views:

16

answers:

1

i hav to read the file with name myname.plist from documents directory .....i want to store the content of the file to string....

+1  A: 

Something like this should do:

/* Find the documents directory. */
NSArray *paths = NSSearchPathForDirectoriesInDomains(
        NSDocumentsDirectory, NSUserDomainMask, YES/*expand tilde*/);
NSAssert([paths count] > 0,
         @"%s: No user document directory found!", __func__);
NSString *documentsDir = [paths objectAtIndex:0U];

/* Build the file path. */
NSString *name = [@"myname" stringByAppendingPathExtension:"plist"];
NSString *path = [documentsDir stringByAppendingPathComponent:name];

/* Read in the file content. */
NSError *error = nil;
NSStringEncoding enc;
NSString *content = [NSString
                     stringWithContentsOfFile:path
                     usedEncoding:&enc
                     error:&error];
if (!content) {
    NSLog(@"%s: Error reading content of \"%@\": %@", __func__, path, error);
}
Jeremy W. Sherman