Browse - Programming Tips - How do I convert a ByteBuffer to a String?

Date: 2013apr28
Language: Java
Class: NIO

Q.  How do I convert a ByteBuffer to a String?

A.  Use the 4-parameter constructor of String

int bytesRead = sc.read(bb); String reply = new String(bb.array(), 0, bytesRead, "UTF-8");