I have a variable named out
that is a BigInteger
.
When trying to get the length of this variable in bits using
out.bitLength();
I receive 46.
If I save this in file using
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("./testBig.dat"));
oos.writeObject(out);
oos.close();
I get a file that is 208 bytes.
Can someone explain to me why those two values differ?
This is because
ObjectOutputStream
stores objects in Java's serialization format; it does not just store the raw content of theBigInteger
object.You can only read the content back by deserializing it, for example with an
ObjectInputStream
.