This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills and have John Sonmez on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes How can I create a byte array from a string? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How can I create a byte array from a string?" Watch "How can I create a byte array from a string?" New topic
Author

How can I create a byte array from a string?

Bruce Jin
Ranch Hand

Joined: Sep 20, 2001
Posts: 671
I have a string �abcdefg�. Can create a byte[] from this string?
Thanks.
Bruce

BJ - SCJP and SCWCD
We love Java programming. It is contagious, very cool, and lot of fun. - Peter Coad, Java Design

Crazy Bikes created by m-Power
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Use the getBytes() method of String. It returns a Byte array.

"JavaRanch, where the deer and the Certified play" - David O'Meara
James Swan
Ranch Hand

Joined: Jun 26, 2001
Posts: 403
If you look at the API for java.lang.String there is a method:
public byte[] getBytes()
Bruce Jin
Ranch Hand

Joined: Sep 20, 2001
Posts: 671
Thanks Cindy.
It works.
Bruce Jin
Ranch Hand

Joined: Sep 20, 2001
Posts: 671
Thanks James!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can I create a byte array from a string?