gpt4 book ai didi

java - (java) 写入文件 little endian

转载 作者:太空狗 更新时间:2023-10-29 22:36:48 26 4
gpt4 key购买 nike

我正在尝试编写 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 等),但我不知道如何让它以小端方式写入。有人知道吗?

最佳答案

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

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();

关于java - (java) 写入文件 little endian,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1394735/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com