Java ByteBuffer convert to String via CharBuffer

Description

Java ByteBuffer convert to String via CharBuffer

import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.FloatBuffer;

public class Main {

   public static void main(String[] args) {

      float[] floats = { 6.61E-39F, 9.91E-39F };

      ByteBuffer bb = ByteBuffer.allocate(floats.length * 4);

      FloatBuffer fb = bb.asFloatBuffer();
      fb.put(floats);//from w  ww  .  j a v  a  2s  .c o  m

      CharBuffer cb = bb.asCharBuffer();
      System.out.println(cb.toString());

   }
}



PreviousNext

Related