Pass your byte array into a new String() contructor:

public String convertToString(byte [] byteArray) {

      String myString = new String(byteArray);

      return myString;
}




|---------+--------------------------->
|         |   "Yan, Hong [IT]"        |
|         |   <[EMAIL PROTECTED]>|
|         |                           |
|         |   27/09/2002 11:24 AM     |
|         |   Please respond to       |
|         |   "JDJList"               |
|         |                           |
|---------+--------------------------->
  
>---------------------------------------------------------------------------------------------------------------|
  |                                                                                    
                           |
  |        To:      "JDJList" <[EMAIL PROTECTED]>                            
                           |
  |        cc:                                                                         
                           |
  |        Subject: [jdjlist] RE: convert a string into a byte array                   
                           |
  
>---------------------------------------------------------------------------------------------------------------|



Alan;

This is a good one, and I really need to look into the API doc. Here is
another question: how to convert a byte array back into a string (smarter
than ... you know what I mean).



Jeff

-----Original Message-----
From: Alan Williamson [mailto:[EMAIL PROTECTED]]
Sent: Friday, September 27, 2002 1:17 PM
To: JDJList
Subject: [jdjlist] RE: convert a string into a byte array


|||          for (int i = 0; i < len; i++)
|||                      myBytes[i] = (byte) myString.charAt(i);
|||
||| Do you have a smarter way of doing this?

Well i really hate to say it ... *BUT* had you read the API docs you would
have found:

-------------------------------------------
java.lang.String

public byte[] getBytes()

             Convert this String into bytes according to the
             platform's default character encoding, storing
             the result into a new byte array.

Returns:
             the resultant byte array.
Since:
             JDK1.1
-------------------------------------------

____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm

Save Bandwidth! Clean up your posts before replying
____________________________________________________

____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm

Save Bandwidth! Clean up your posts before replying
____________________________________________________



This message is for the designated recipient only and may contain
privileged, proprietary, or otherwise private information.  If you have
received it in error, please notify the sender immediately and delete the
original.  Any other use of the email by you is prohibited.


____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm

Save Bandwidth! Clean up your posts before replying
____________________________________________________

Reply via email to