JAVA - Write binary number to a file and read it -


how can write file binary number without cut zeros .

i'm writing :

byte[] b = new biginteger("1011010101010110", 2).tobytearray();  fileoutputstream fos = new fileoutputstream("file",true); fos.write(b); 

but example : when write 0000001, writes in file 1 , ignores zeros, same happens if write 001001001000 , ignores zeros on left reading 8bits @ time right left.

what correct way write binary digits file ? if correct way, i'm might trying read file in wrong way ( i'm using read() of inputstream )

ps-(8 digits must 1 byte writing string not option, cause each digit 1 byte.)

you can try this

    string s = "0000001";     byte[] = new byte[s.length()];     (int = 0; < s.length(); i++) {         a[i] = (byte) (s.charat(i) & 1);     } 

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -