Sometimes, we need to place a binary or bytecode file in the package. How can we read its content?
[Cpp] // obtain the file path (note that it is a full path)
NSString * path = [[NSBundle mainBundle] pathForResource: @ "data" ofType: @ "bin"];
// Obtain data
NSData * reader = [NSData dataWithContentsOfFile: path];
// Obtain the object length (size)
Int size = [reader length];
// Read 4 bytes from the start position
Int nData = 0;
[Reader getBytes: & nData range: NSMakeRange (0, 4)];
// Read the specified length from the specified position (offset)
Char dataBuf [100];
Int offset = 150;
[Reader getBytes: & dataBuf range: NSMakeRange (offset, 100)];
// Obtain the file path (note that it is a full path)
NSString * path = [[NSBundle mainBundle] pathForResource: @ "data" ofType: @ "bin"];
// Obtain data
NSData * reader = [NSData dataWithContentsOfFile: path];
// Obtain the object length (size)
Int size = [reader length];
// Read 4 bytes from the start position
Int nData = 0;
[Reader getBytes: & nData range: NSMakeRange (0, 4)];
// Read the specified length from the specified position (offset)
Char dataBuf [100];
Int offset = 150;
[Reader getBytes: & dataBuf range: NSMakeRange (offset, 100)];