本文介绍了(java)在文件little endian中编写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写TIFF IFD,我正在寻找一种简单的方法来执行以下操作(此代码显然是错误的,但它可以解决我想要的问题):

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)

会写:

0c00 0301 0300 0100 0000 0100 0000

0c00 0301 0300 0100 0000 0100 0000

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

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?

推荐答案

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

Maybe you should try something like this:

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)在文件little endian中编写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 21:32