I want to write a BigInteger to a file.
What is the best way to do this.
Of course I want to read (with the program, not by human) it from an inputstream.
Do I have to use an ObjectOutputStream or are there better ways?
The purpose is to use as less bytes as possible.
Thanks
Martijn
Java serialisation (
ObjectOutputStream/ObjectInputStream) is a general purpose way of, er, serialising objects into octet sequences. However, there are issue with serialisation.To be uber efficient,
BigIntegerhastoByteArrayand a constructor that takesbyte[]. Then you need some way to representbyte[](including length) in a stream. For instance, you could useDataOutputStreamtowriteIntthe length, and follow that with the raw data.Streams can, of course, be compressed with a suitable decorator of your choice.