Java Tutorial/File/DoubleBuffer — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 05:20, 1 июня 2010
Convert ByteBuffer to DoubleBuffer
import java.nio.ByteBuffer;
import java.nio.DoubleBuffer;
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();
DoubleBuffer db = ((ByteBuffer) bb.rewind()).asDoubleBuffer();
System.out.println("Double Buffer");
while (db.hasRemaining())
System.out.println(db.position() + " -> " + db.get());
}
}
/*
*
*/
Double Buffer 0 -> 4.8E-322
Create a DoubleBuffer
import java.nio.ByteBuffer;
import java.nio.DoubleBuffer;
public class Main {
public static void main(String[] argv) throws Exception {
ByteBuffer buf = ByteBuffer.allocate(15);
DoubleBuffer dbuf = buf.asDoubleBuffer();
}
}
Use While loop to read a DoubleBuffer
import java.nio.ByteBuffer;
import java.nio.DoubleBuffer;
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();
DoubleBuffer db = ((ByteBuffer) bb.rewind()).asDoubleBuffer();
System.out.println("Double Buffer");
while (db.hasRemaining())
System.out.println(db.position() + " -> " + db.get());
}
}
/*
*
*/
Double Buffer 0 -> 4.8E-322