write Float to FileOutputStream - Java java.io

Java examples for java.io:OutputStream

Description

write Float 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 writeFloat(FileOutputStream bos, float someFloat) throws IOException {
    byte[] bytes = ByteBuffer.allocate(Float.SIZE / Byte.SIZE).order(BYTE_ORDER_LE).putFloat(someFloat).array();
    bos.write(bytes);/*from w  w  w  . j  a va  2  s. com*/
  }
}

Related Tutorials