Skip to content
Advertisement

ByteArrayInputStream cannot read long with ByteArrayOutputStream written in Java

I have a read code for a long number like below;

JavaScript

I have write file like below;

JavaScript

When I try to store a big value like 253402300799999L, the reading result is totally different. For small values the code runs fine. Assuming that changing read code is not possible, how can I fix this issue. thanks in advance.

Advertisement

Answer

Your reading code is incorrect.

You need to cast int to long before shift (<<).

JavaScript

So if you can’t change your read code it is impossible to fix your problem.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement