Java RandomAccessFile read() returning 0x00

0

I'm using a Java RandomAccessFile seeking to 0x000000A0 of my file, then reading from that location into a byte array. However, every byte I read comes out to be 0x00. I'm not modifying the file anywhere else in this program, this is the only place. Also I know for a fact that there is data at 0x000000A0 of my file. Here it is:

public static String getGameCode() throws IOException
{
    RandomAccessFile raf = new RandomAccessFile(file, "rw");
    byte[] bytes = new byte[0x10];
    raf.seek(0x0000A0);
    raf.read(bytes);
    raf.close();

    for(byte b : bytes) {
        System.out.println(String.format("0x%02X", b));
    }

    return new String(bytes);
}
java
asked on Stack Overflow May 12, 2020 by Marina Terry

1 Answer

1

Turns out my 32MB file was somehow erased and therefore was 0KB. I just replaced the file with a good copy and it works fine. Remember to confirm the size of your file!

answered on Stack Overflow May 12, 2020 by Marina Terry

User contributions licensed under CC BY-SA 3.0