CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Java >  J2SE / 基础类

String怎么转换为byte[]?

楼主Karnak(卡纳克神庙)2002-04-01 10:54:50 在 Java / J2SE / 基础类 提问

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

相关问题

  • 怎么实现byte[] 和 string 的转换?
  • 怎么样将string转换为byte数组和byte数组转换为string?
  • string转换成byte???
  • 特急!怎么从string转换到byte[] abc中?
  • byte如何转换成String?
  • BYTE数组和String转换
  • ********!sqlBinary怎么转换成byte[]!********
  • 怎么把String转换float?
  • int 怎么转换成string ?
  • 如何将String 转换为byte[] ?!

关键词

  • 文档
  • jdk
  • byt
  • getbytespublic
  • getbytes
  • byte
  • abcdefg
  • 帮助
  • according
  • jdk1.1

得分解答快速导航

  • 帖主:Karnak
  • tehcon
  • kicku
  • GJA106
  • lfxhyf7979
  • zjp009

相关链接

  • CSDN Java频道
  • Java类图书
  • Java类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo