(java) 写入文件小端
我正在尝试编写 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 等),但我不知道如何让它以小尾数法写入。有人知道吗?
I'm trying to write TIFF IFDs, and I'm looking for a simple way to do the following (this code obviously is wrong but it gets the idea across of what I want):
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)
Would write:
0c00 0301 0300 0100 0000 0100 0000
I know how to get the writing method to take up the correct number of bytes (writeInt, writeChar, etc) but I don't know how to get it to write in little endian. Anyone know?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
也许你应该尝试这样的事情:
Maybe you should try something like this:
ByteBuffer 显然是更好的选择。您还可以编写一些像这样的便利函数,
ByteBuffer is apparently the better choice. You can also write some convenience functions like this,
查看 ByteBuffer,特别是 ' 订单< /a>' 方法。对于我们这些需要与 Java 之外的任何东西进行交互的人来说,ByteBuffer 是一个福音。
Check out ByteBuffer, specifically the 'order' method. ByteBuffer is a blessing for those of us who need to interface with anything not Java.