aspose file tools*
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 666
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: 666
Thanks Cindy.
It works.
Bruce Jin
Ranch Hand

Joined: Sep 20, 2001
Posts: 666
Thanks James!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can I create a byte array from a string?
 
Similar Threads
Concatenate->Print OR System.out.print() ???
NX: URLyBird 1.1.3 Find criteria
How to write back an updated record to db file?
can i transform the Byte array to a String ?
Convert byte to its hex format?