Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

String.getBytes() deprecated?

1,680 views
Skip to first unread message

Tristan Colgate

unread,
Jul 14, 1997, 3:00:00 AM7/14/97
to

Hi,

I keep getting a compiler warning saying that getBytes has been
deprocated and that I should stop using it, the thing is I cant seem to
figure out what I am supposed to replace it with, Sun's API reference didnt
help.

I'm trying to write some code to implement a few e-mail protocols so
getBytes is kind of useful!

Thanks in advance for any help,

Tristan Colgate
<col...@dcs.kcl.ac.uk>
PGP key available on request.


Allan Boyd

unread,
Jul 15, 1997, 3:00:00 AM7/15/97
to Tristan Colgate

--------------008DA0693331E0A79342C2A7
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

JDK 1.1.3 API ref. says the following about String.getBytes(int, int,
byte, int) - apparently this is the only getBytes that is deprecated.


> Note: getBytes() is deprecated. This method does not properly convert characters into bytes. As of JDK 1.1,
> the preferred way to do this is via the getBytes(String enc) method, which takes a character-encoding name,
> or the getBytes() method, which uses the platform's default encoding.
>


Tristan Colgate wrote:

--
Allan Boyd
Java Technology Centre
IBM Hursley UK Laboratory

e-mail:ab...@hursley.ibm.com


--------------008DA0693331E0A79342C2A7
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<HTML>
JDK 1.1.3 API ref. says the following about String.getBytes(int, int, byte,
int) - apparently this is the only getBytes that is deprecated.
<BR>&nbsp;
<BLOCKQUOTE TYPE=CITE>
<PRE>Note: getBytes() is deprecated. This method does not properly convert characters into bytes. As of JDK 1.1,
&nbsp;&nbsp;&nbsp;&nbsp; the preferred way to do this is via the getBytes(String enc) method, which takes a character-encoding name,
&nbsp;&nbsp;&nbsp;&nbsp; or the getBytes() method, which uses the platform's default encoding.</PRE>
</BLOCKQUOTE>
&nbsp;

<P>Tristan Colgate wrote:
<BLOCKQUOTE TYPE=CITE>Hi,

<P>&nbsp; I keep getting a compiler warning saying that getBytes has been
<BR>deprocated and that I should stop using it, the thing is I cant seem
to
<BR>figure out what I am supposed to replace it with, Sun's API reference
didnt
<BR>help.

<P>&nbsp; I'm trying to write some code to implement a few e-mail protocols
so
<BR>getBytes is kind of useful!

<P>&nbsp; Thanks in advance for any help,

<P>&nbsp; Tristan Colgate
<BR>&nbsp; &lt;col...@dcs.kcl.ac.uk>
<BR>&nbsp; PGP key available on request.</BLOCKQUOTE>
&nbsp;

<P>--
<BR>Allan Boyd
<BR>Java Technology Centre
<BR>IBM Hursley UK Laboratory

<P>e-mail:ab...@hursley.ibm.com
<BR>&nbsp;</HTML>

--------------008DA0693331E0A79342C2A7--


David Wilkinson

unread,
Jul 16, 1997, 3:00:00 AM7/16/97
to

On 14 Jul 1997 21:44:27 GMT, "Tristan Colgate" <col...@dcs.kcl.ac.uk> wrote:

>Hi,
>
> I keep getting a compiler warning saying that getBytes has been
>deprocated and that I should stop using it, the thing is I cant seem to
>figure out what I am supposed to replace it with, Sun's API reference didnt
>help.

If you read the 'getBytes' entry, it tells you exactly what you should replace
it with. From the API docs for String.getBytes(int, int, byte[], int) :

>Note: getBytes() is deprecated. This method does not properly convert characters
>into bytes. As of JDK 1.1, the preferred way to do this is via the getBytes(String enc)
>method, which takes a character-encoding name, or the getBytes() method, which uses
>the platform's default encoding.

So code that used to say:

String s;
:
:
int len = 1024;
byte b[] = new byte[len];
s.getBytes(0, len, b, 0);

should be replaced by:

String s;
:
:
byte b[] = s.getBytes();
int len = b.length;

Dave W.


--
David Wilkinson | If people listened to themselves
http://www.cascade.org.uk/ | more often, they would talk less.
Usual Disclaimers Apply |

0 new messages