How can i write to a file a binary number without it to cut the zeros .
I'm writing like this :
byte[] b = new BigInteger("1011010101010110", 2).toByteArray();
FileOutputStream fos = new FileOutputStream("file",true);
fos.write(b);
But then for example : When i write 0000001, it writes in the file just 1 and ignores the zeros, the same happens if i write 001001001000 , it ignores the zeros on the left reading 8bits at the time from the right to the left.
What is the correct way to write binary digits to a file ? If this is the correct way, i'm might be trying to read the file in the wrong way ( I'm using the read() of InputStream )
Ps-(8 digits must be 1 byte so writing as a string is not an option, cause each digit is 1 byte.)