F
F
FALSHER_DEV2021-05-30 11:34:46
Java
FALSHER_DEV, 2021-05-30 11:34:46

The FileReader ignores the first two bytes. What's the matter?

I have the simplest code to test the operation of FileReader:

Code/Java
Reader r = new FileReader("1234.dmap");
System.out.println(Integer.toHexString(r.read()));
System.out.println(Integer.toHexString(r.read()));
System.out.println(Integer.toHexString(r.read()));
System.out.println(Integer.toHexString(r.read()));

Actually, the file itself:
1234.dmap
EB AF 3D 1A 63 6F 6D 2E

And the console output after executing the code:
Conclusion

fffd
3d
1a
63

As you can see, FileReader completely ignores the first two bytes, in addition, the size of the first byte is oversized. At the same time, everything works fine with FileInputStream
Help me figure out the problem

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
nApoBo3, 2021-05-30
@FALSHER_DEV

FileReader is not designed to read "raw" data, it reads text data taking into account the system encoding.
https://javarush.ru/help/7579

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question