0

I want to write a byte array to file. This is code in the web http://allmybrain.com/2012/03/16/quick-convert-raw-g711-ulaw-audio-to-a-au-file/

    import struct
    header = [ 0x2e736e64, 24, 0xffffffff, 1, 8000, 1 ]
    o=open('out.au','wb')
    o.write ( struct.pack ( ">IIIIII", *header ) )
    raw = open('in.raw','rb').read()
    o.write(raw)
    o.close()

And I converted to java :

            byte []  header= {   0x2e736e64, 24, 0xffffffff, 1, 8000, 1 };
        FileOutputStream out = new FileOutputStream(file);
        out.write(header);

But it is error. Can you help me to fix it. Thanks

john2182
  • 117
  • 3
  • 11

1 Answers1

6

In your python code your are writting 32bits integers and not 8bits bytes; You can have the same result with this code :

 byte []  header= {   0x2e, 0x73, 0x6e, 0x64,
                      0x0,  0x0,  0x0,  24,
                      -1,  -1,    -1,   -1,
                      0,   0,     0,    1,
                      0,   0,     0x1f, 0x40,
                      0,   0,     0,    1 };
 FileOutputStream out = new FileOutputStream(file);
 out.write(header);
speedblue
  • 486
  • 3
  • 11