Dave's Brain

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");

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.