This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Java in General and the fly likes String into byte buffer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "String into byte buffer" Watch "String into byte buffer" New topic

String into byte buffer

chella adisesh

Joined: Oct 10, 2003
Posts: 7
Wanted to know how to convert a string into a byte buffer.
Also can someone give me links or books to -
* converting byte buffer to string.
* converting string to bytebuffer.
* converting string to string buffer.
* converting string to char buffer.
Wirianto Djunaidi
Ranch Hand

Joined: Mar 20, 2001
Posts: 210

Check out the javadoc on
especially String.getBytes(), String.getChars() and String(bytes[])
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
Previously you were asking about ByteBuffer and CharBuffer. (Capitalization is important in Java.) You can convert a String to a CharBuffer using CharBuffer.wrap(CharSequence) (note that a String is also a CharSequence) and then you can use a CharsetEncoder to convert the CharBuffer to a ByteBuffer. It's much like the answer to your previous question, but in reverse. Study the APIs for the classes and methods that have been mentioned here; they contain explanations for how each of these works.

"I'm not back." - Bill Harding, Twister
I agree. Here's the link:
subject: String into byte buffer
It's not a secret anymore!