write Short to FileOutputStream - Java java.io

Java examples for java.io:OutputStream

Description

write Short 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 writeShort(FileOutputStream bos, short someShort)
            throws IOException {
        byte[] bytes = ByteBuffer.allocate(Short.SIZE / Byte.SIZE)
                .order(BYTE_ORDER_LE).putShort(someShort).array();
        bos.write(bytes);//from   w  w w  . j  a  va 2s .c om
    }
}

Related Tutorials