I'm going to quote Alan's excellent lead-in here:

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

String

public String(byte[] bytes)

    Constructs a new String by decoding the specified array of bytes using 
the platform's default charset. The length of the new String is a function 
of the charset, and hence may not be equal to the length of the byte array.

    The behavior of this constructor when the given bytes are not valid in 
the default charset is unspecified. The CharsetDecoder class should be used 
when more control over the decoding process is required.

Parameters:
bytes - the bytes to be decoded into charactersSince:
JDK1.1

This is from the (rather misleading) Java API docs, url: 
http://java.sun.com/j2se/1.4/docs/api/java/lang/String.html#String(byte[])

This is a RETARDED QUESTION, esp. after being pointed to the API docs in the 
first place. I'm going to pretend you're a troll, so pretend your killfiled. 
Your name's not Tim, is it?

>From: "Yan, Hong [IT]" <[EMAIL PROTECTED]>
>Reply-To: "JDJList" <[EMAIL PROTECTED]>
>To: "JDJList" <[EMAIL PROTECTED]>
>Subject: [jdjlist] RE: convert a string into a byte array
>Date: Fri, 27 Sep 2002 13:24:45 -0400
>
>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
>____________________________________________________


-----------------------------------------------
Joseph B. Ottinger       [EMAIL PROTECTED]
http://enigmastation.com          IT Consultant

_________________________________________________________________
Join the world�s largest e-mail service with MSN Hotmail. 
http://www.hotmail.com


____________________________________________________
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