mardi 28 avril 2015

Writing byte to file then reading yields different byte

I have a program that needs to read and write RGB values from a file. However, I encountered an issue with the application where the data I am reading back from a file differs from what I was writing to it.

Program:

public static void main(String[] args) throws Exception {
    FileOutputStream fos = new FileOutputStream(new File("ASDF.txt"));
    fos.write(0xFF95999F);
    fos.flush();
    fos.close();
    FileInputStream fis = new FileInputStream(new File("ASDF.txt"));
    byte read;
    while((read = (byte) fis.read()) != -1) {
        System.out.print(String.format("%02X ", read));
    }
    fis.close();
}

Output:

9F

Aucun commentaire:

Enregistrer un commentaire