The Artima Developer Community
Sponsored Link

Java Buzz Forum
How to convert ByteBuffer to String in Java

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Javin Paul

Posts: 1090
Nickname: javinpaul
Registered: Jan, 2012

Javin Paul is Java Programmer working on Finance domain.
How to convert ByteBuffer to String in Java Posted: Jun 8, 2015 10:14 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Javin Paul.
Original Post: How to convert ByteBuffer to String in Java
Feed Title: Java67
Feed URL: http://www.java67.com/feeds/posts/default?alt=rss
Feed Description: Java and technology tutorials, tips, questions for all programmers.
Latest Java Buzz Posts
Latest Java Buzz Posts by Javin Paul
Latest Posts From Java67

Advertisement
You can easily convert ByteBuffer to String  in Java if you know how to convert byte array to String. Why? because its very easy to convert ByteBuffer to byte array and vice versa. All you need to do is call the ByteBuffer.array() method, it will return you the byte array used by java.nio.ByteBuffer class, later you can easily create String from that byte array. Though always remember to provide correct character encoding while converting byte array to String. For example, if you know that ByteBuffer is filled with bytes encoded in UTF-8 then you must use same encoding while creating String from that byte array. String class provides an overloaded constructor which accepts character encoding along with byte array.  You can the snippet shared in this example to do the job. ByteBuffer is one of the very useful class in java.nio package which is used to read data from channels and write data into channel directly. Same ByteBuffer can be used to read and write data. If you want to read from ByteBuffer just call the flip() method and it will convert ByteBuffer into reading mode. In this article, you will learn how to convert ByteBuffer to String in Java. I have a given a simple example, but if you still any doubt you can always leave a comment or question.
Read more »

Read: How to convert ByteBuffer to String in Java

Topic: How to find If Number Power of Two Using Bitwise Operator Previous Topic   Next Topic Topic: Java Tutorial : Eclipse Setup

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use