NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"a.plist"];
NSMutableDictionary *plistContents = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
How to access files at a path NSURL
Question
Hello everyone i have the following code :
NSString* issuePath =[[self contentURL] URLByAppendingPathComponent:@"magazine"].path;
I have a file called a.plist in the above directory. I have to read the a.plist file contents. How to do that. Before the file was local and I was accessing it as follows
NSString *path = [[NSBundle mainBundle] pathForResource:@"a" ofType:@"plist"];
La solution
Autres conseils
Refer this file handler utility which provides API's to interact with most of your file related operations.
It exposed API for below features,
- Check if the file, or directory, exists in the given path
- Create a folder in a given path
- Verify if a folder exists at a given path
- Get the size of a file
- Check if a file with that name exists in the folder
- Check if this folder has more subfolder or if it's the last folder
File Handler Utility Class link
You can simply use the following method.
NSString *path = [[NSBundle mainBundle] pathForResource:@"a" ofType:@"plist"];
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow