String转byte[]

来源:互联网 发布:万方数据库免费注册 编辑:程序博客网 时间:2024/05/17 07:29
//string 转 byte[]String str = "Hello";byte[] srtbyte = str.getBytes();// byte[] 转 stringString res = new String(srtbyte);System.out.println(res);//当然还有可以设定编码方式的String str = "hello";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 blocke.printStackTrace();    }

版权声明:本文为博主原创文

0 0
原创粉丝点击