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.
--------------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
--------------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>
<BLOCKQUOTE TYPE=CITE>
<PRE>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.</PRE>
</BLOCKQUOTE>
<P>Tristan Colgate wrote:
<BLOCKQUOTE TYPE=CITE>Hi,
<P> 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> I'm trying to write some code to implement a few e-mail protocols
so
<BR>getBytes is kind of useful!
<P> Thanks in advance for any help,
<P> Tristan Colgate
<BR> <col...@dcs.kcl.ac.uk>
<BR> PGP key available on request.</BLOCKQUOTE>
<P>--
<BR>Allan Boyd
<BR>Java Technology Centre
<BR>IBM Hursley UK Laboratory
<P>e-mail:ab...@hursley.ibm.com
<BR> </HTML>
--------------008DA0693331E0A79342C2A7--
>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 |