码迷,mamicode.com
首页 > 编程语言 > 详细

java里面byte数组和String字符串转换

时间:2015-04-24 12:34:24      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:编码

//string 转 byte[]
String str = "问题";
byte[] srtbyte = str.getBytes();
// byte[] 转 string
String res = new String(srtbyte);
System.out.println(res);
当然还有可以设定编码方式
String str = "问题";
 byte[] srtbyte = null;
 try {
 srtbyte = str.getBytes("UTF-8");
 String res = new String(srtbyte,"UTF-8");
 System.out.println(res);
 } catch (UnsupportedEncodingException e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
 }


java里面byte数组和String字符串转换

标签:编码

原文地址:http://blog.csdn.net/xiaokui_wingfly/article/details/45244693

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!