在Java中,当使用DataOutputStream写入文件时,如何定义正在写入的数据的Endian?

我正在使用DataOutputStream写入文件,但是我想更改数据的endian.

这就是我将字节数据写入文件的方式(认情况下以Little end输出)

public void generateBinObjFile(String outputFile)
    try {
        // Create file

        DataOutputStream stream = new DataOutputStream(
                new FileOutputStream(outputFile));

        stream.writeShort(this.quantize(this.xComponents.get(index),//<-- Short is written in little Endian
                    this.min_x,this.max_x) - 32768);

        } // catch statements here

有没有办法可以定义字节数据用Java编写的Endian?

解决方法

你不能用DataOutputStream来做这件事,它总是使用大端.

您可以使用ByteBuffer调用order()以影响其读取和写入数据的方式.

您可以使用ByteBuffer来准备一个byte [],您将在稍后使用经典的OutputStream编写或完全转到NIO并使用任何WritableByteChannel进行写入

相关文章

最近看了一下学习资料,感觉进制转换其实还是挺有意思的,尤...
/*HashSet 基本操作 * --set:元素是无序的,存入和取出顺序不...
/*list 基本操作 * * List a=new List(); * 增 * a.add(inde...
/* * 内部类 * */ 1 class OutClass{ 2 //定义外部类的成员变...
集合的操作Iterator、Collection、Set和HashSet关系Iterator...
接口中常量的修饰关键字:public,static,final(常量)函数...