I want to write a BigInteger to a file, but I want to prepend it with the lenght of the integer, so I know how long it is when I read it again (the file wih have several bigints)
I know I can convert it to a byte array using bigInteger.toByteArray(), but then to prepend this array with its length the only way I can think of is to create another array and copy it. I don't want to do that since it will basically double the time I would take to write the file, and waste time and memory.
Is there any other, more efficient method?
Edit: Looking at the comments - I'm doing this because I want to put multiple bigints in a single file, and so I can use the length as delimiter of sorts.