String怎么转换为byte[]?
String str ="abcdefg";
byte[] byt =new byte[20];
怎么能够把str赋给byt[]?
问题点数:20、回复次数:6Top
1 楼tehcon(信我者得永生)回复于 2002-04-01 11:03:48 得分 4
为什么不用getBytes()?
Top
2 楼kicku(Lavender's Lover)回复于 2002-04-01 11:11:19 得分 4
byte[] byt = str.getBytes();
or use System.ArrayCopy.....Top
3 楼GJA106(中文字符)回复于 2002-04-01 11:12:25 得分 4
String str ="abcdefg";
byte[] byt =new byte[20];
改为:
String str ="abcdefg";
byte[] byt =str.getBytes();
如果不想这样你也可以用个循环来getByte();Top
4 楼lfxhyf7979(匿名类)回复于 2002-04-01 11:13:19 得分 4
getBytes
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
摘自java的帮助文档,多看看文档对学java帮助很大。
Top
5 楼lfxhyf7979(匿名类)回复于 2002-04-01 11:14:29 得分 0
getBytes
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
摘自java的帮助文档,多看看文档对学java帮助很大。
Top
6 楼zjp009(高手)回复于 2002-04-01 11:19:00 得分 4
对,用getBytes(),功能强大。
Top
7 楼lfxhyf7979(匿名类)回复于 2002-04-01 11:24:45 得分 0
getBytes
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
多看看java文档,对学习java帮助会很大Top
8 楼Karnak(卡纳克神庙)回复于 2002-04-01 11:25:14 得分 0
我试过byte[] byt =str.getBytes("Unicode");
原来不用加参数,谢了,给分!
Top




