get String from ByteBuffer - Java java.nio

Java examples for java.nio:ByteBuffer String

Description

get String from ByteBuffer

Demo Code


//package com.java2s;
import java.nio.ByteBuffer;

public class Main {
    public static String getString(ByteBuffer buf) {
        char len = buf.getChar();
        StringBuilder sb = new StringBuilder(len);
        for (int i = 0; i < len; i++) {
            sb.append(buf.getChar());// w  w w . j av  a2 s.  c om
        }
        return sb.toString();
    }
}

Related Tutorials