Java examples for File Path IO:Byte Array
Converts a float to a byte array with a length of 4.
//package com.java2s; import java.nio.ByteBuffer; public class Main { public static void main(String[] argv) throws Exception { float f = 2.45678f; System.out.println(java.util.Arrays.toString(floatToByteArray(f))); }// w w w . j ava 2 s .co m /** * Converts a float to a byte array with a length of 4. * @param f - The float. * @return The byte array. */ public static byte[] floatToByteArray(float f) { return ByteBuffer.allocate(4).putFloat(f).array(); } }