Java Tutorial/File/FloatBuffer
Версия от 17:44, 31 мая 2010; (обсуждение)
Convert ByteBuffer to a FloatBuffer
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
public class MainClass {
public static void main(String[] args) {
ByteBuffer bb = ByteBuffer.wrap(new byte[] { 0, 0, 0, 0, 0, 0, 0, "a" });
bb.rewind();
FloatBuffer fb = ((ByteBuffer) bb.rewind()).asFloatBuffer();
System.out.println("Float Buffer");
while (fb.hasRemaining())
System.out.println(fb.position() + " -> " + fb.get());
}
}
/*
*/
Float Buffer 0 -> 0.0 1 -> 1.36E-43
Use while loop to read a FloatBuffer
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
public class MainClass {
public static void main(String[] args) {
ByteBuffer bb = ByteBuffer.wrap(new byte[] { 0, 0, 0, 0, 0, 0, 0, "a" });
bb.rewind();
FloatBuffer fb = ((ByteBuffer) bb.rewind()).asFloatBuffer();
System.out.println("Float Buffer");
while (fb.hasRemaining())
System.out.println(fb.position() + " -> " + fb.get());
}
}
/*
*/
Float Buffer 0 -> 0.0 1 -> 1.36E-43