write Int to FileOutputStream - Java java.io

Java examples for java.io:OutputStream

Description

write Int to FileOutputStream

Demo Code


import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;

public class Main{
    private static final ByteOrder BYTE_ORDER_LE = ByteOrder.LITTLE_ENDIAN;
    public static void writeInt(FileOutputStream bos, int someInt)
            throws IOException {
        byte[] bytes = ByteBuffer.allocate(Float.SIZE / Byte.SIZE)
                .order(BYTE_ORDER_LE).putInt(someInt).array();
        bos.write(bytes);/*from  w ww  .j  a  v a2 s . c  o  m*/
    }
}

Related Tutorials