Tuesday, April 23, 2013

NSData dataWithContentsOfFile example ios


dataWithContentsOfFile:

Creates and returns a data object by reading every byte from the file specified by a given path.
+ (id)dataWithContentsOfFile:(NSString *)path
Parameters
path
The absolute path of the file from which to read data.
Return Value
A data object by reading every byte from the file specified by path. Returns nil if the data object could not be created.
Discussion
This method is equivalent to dataWithContentsOfFile :options:error: with no options. If you need to know what was the reason for failure, use dataWithContentsOfFile :options:error:.
Example of [NSData dataWithContentsOfFile]

NSMutableString *sss;
sss=[[NSMutableString  alloc] initWithString: [[NSBundle mainBundle] resourcePath]];
[sss appendString:@"/"] ;
[sss appendString:@"thumbnail.png"];
NSData *imageData = [NSData dataWithContentsOfFile:sss];
---------------------------------------------------------------------------
NSMutableString *sss;
sss=[[NSMutableString  alloc] initWithString: [[NSBundle mainBundle] resourcePath]];
[sss appendString:@"/"] ;
[sss appendString:@"original.png"];
NSData *imageData = [NSData dataWithContentsOfFile:sss];