write Long to FileOutputStream - Java java.io

Java examples for java.io:OutputStream

Description

write Long 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 writeLong(FileOutputStream bos, long someLong)
            throws IOException {
        byte[] bytes = ByteBuffer.allocate(Long.SIZE / Byte.SIZE)
                .order(BYTE_ORDER_LE).putLong(someLong).array();
        bos.write(bytes);/*from  w ww  .  j  av a 2  s.  co  m*/
    }
}

Related Tutorials