Iam trying to read a binary file to memory and pass the starting address of the memory block to a native function:
Memory image = new Memory(length);
int offset = 0;
int numRead = 0;
try
{
while (offset < image.size() && (numRead = in.read(image.getByteArray(0,(int)image.size()), offset, (int)image.size() - offset)) >= 0)
{
offset += numRead;
}
if (offset < image.size())
{
throw new IOException("Could not completely read file " + fileFileName.getName());
}
in.close();
}
catch(Exception IOException)
{
System.out.println("\nError Occured in try block!!!");
}
byte imageByte = image.getByte(0);
The problem is that the value of imageByte is -60 instead of 127. I checked by taking a byte array(instead of Memory) and reading the file into it. But it too showed 127 for array[0]. What can be the problem here???
ok i resolved the problem 😀 since getByteArray() returns a new byte array, the data was being copied to that new byte array and the memory region that i want to use remained uninitialised