集册 Java实例教程 获取和设置非

获取和设置非

欢马劈雪     最近更新时间:2020-01-02 10:19:05

508
在ByteBuffer中获取和设置非字节Java类型
/**来 自 N o  w  J a v a . c o m - 时  代  Java**/

import java.nio.ByteBuffer;


public class Main {

  public static void main(String[] args) {

    // Obtain a ByteBuffer; see also Creating a ByteBuffer

    ByteBuffer buf = ByteBuffer.allocate(100);


    // Put values of different types

    buf.putChar((char) 123);

    buf.putShort((short) 123);

    buf.putInt(123);

    buf.putLong(123L);

    buf.putFloat(12.3F);
    /*
    N o w J a v a . c o m 提 供
    */

    buf.putDouble(12.3D);


    // Reset position for reading

    buf.flip();


    // Retrieve the values

    char c = buf.getChar();

    short s = buf.getShort();

    int 
展开阅读全文