如何用Java将字节数组写入文件
我想把字节数组写入文件。这是网页上的代码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()
我转换成了java:
byte [] header= { 0x2e736e64, 24, 0xffffffff, 1, 8000, 1 };
FileOutputStream out = new FileOutputStream(file);
out.write(header);
但这是错误的。你能帮我修一下吗。谢谢
# 1 楼答案
在python代码中,你写的是32位整数,而不是8位字节; 使用此代码可以得到相同的结果: