tags:

views:

533

answers:

1

Hi

I am an NSURL object which gives me the path of a local file (in documents folder). I want to populate an NSData object with the contents of this file. Tried using dataWithContentsOfURL: but this fails. I know the file exists because the iPhone SDK returns the path.

Can someone please tell me how I can get an NSData object from the URL of a local file.

Thanks.

+2  A: 
// Given some file path URL: NSURL *pathURL
// Note: [pathURL isFileURL] must return YES
NSString *path = [pathURL path];
NSData *data = [[NSFileManager defaultManager] contentsAtPath:path];
Tim
contentsOfFile takes an NSString with the file path. I am getting an NSURL object.
lostInTransit
Sorry; noticed that after I answered. Edited.
Tim
Thanks a lot Tim.
lostInTransit