首页 > 代码库 > 常用编码测试
常用编码测试
1 public static void main(String[] args) { 2 String s = "你好"; 3 String cn = ""; 4 System.out.println("src: " + s); 5 try { 6 7 byte[] bs = s.getBytes("utf-8"); 8 System.out.println(Arrays.toString(bs));; 9 //[-28, -67, -96, -27, -91, -67]10 cn = new String(bs, "utf-8");11 System.out.println(cn);12 //你好13 cn = new String(bs, "gbk");14 System.out.println(cn);15 //浣犲ソ16 17 bs = s.getBytes("gbk");18 System.out.println(Arrays.toString(bs));19 //[-60, -29, -70, -61]20 21 cn = new String(bs, "gbk");22 System.out.println(cn);23 //你好24 cn = new String(bs, "utf-8");25 System.out.println(cn);26 //???27 } catch (UnsupportedEncodingException e) {28 e.printStackTrace();29 }30 }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。