(java)在文件little endian中写入

托尼·史塔克(Tony Stark):

我正在尝试编写TIFF IFD,并且我正在寻找一种简单的方法来执行以下操作(此代码显然是错误的,但可以将其理解为我想要的东西):

out.writeChar(12) (bytes 0-1)
out.writeChar(259) (bytes 2-3)
out.writeChar(3) (bytes 4-5)
out.writeInt(1) (bytes 6-9)
out.writeInt(1) (bytes 10-13)

会写:

0c00 0301 0300 0100 0000 0100 0000

我知道如何使写入方法占用正确的字节数(writeInt,writeChar等),但我不知道如何使其以小尾数法写入。有人知道吗

xap4o:

也许您应该尝试这样的事情:

ByteBuffer buffer = ByteBuffer.allocate(1000); 
buffer.order(ByteOrder.LITTLE_ENDIAN);         
buffer.putChar((char) 12);                     
buffer.putChar((char) 259);                    
buffer.putChar((char) 3);                      
buffer.putInt(1);                              
buffer.putInt(1);                              
byte[] bytes = buffer.array();     

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章