String转化为byte[]和byte[]转化为String

来源:互联网 发布:碧之轨迹优化破解补丁 编辑:程序博客网 时间:2024/05/17 01:19

(转载)http://stackoverflow.com/questions/6684665/java-byte-array-to-string-to-byte-array

String coolString = "cool string";byte[] byteArray = coolString.getBytes();String reconstitutedString = new String(byteArray);System.out.println(reconstitutedString);

byte[] b = string.getBytes();byte[] b = string.getBytes(Charset.forName("UTF-8"));byte[] b = string.getBytes(StandardCharsets.UTF_8); // Java 7+ only

0 0
原创粉丝点击