Reputation: 1636
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?
Upvotes: 0
Views: 73
Reputation: 206806
This is because ObjectOutputStream
stores objects in Java's serialization format; it does not just store the raw content of the BigInteger
object.
You can only read the content back by deserializing it, for example with an ObjectInputStream
.
Upvotes: 2