字符编码
2016-05-09 15:26
288 查看
package 练习; import java.io.UnsupportedEncodingException; public class 编码 { public static void main(String []args) throws UnsupportedEncodingException{ String string = "你好ABC"; byte[] byte1 = string.getBytes("utf-8"); //utf-8编码采用的汉字占三个字节,字母一个字节 for (byte b : byte1) { System.out.print(Integer.toHexString(b & 0xff) + " "); } System.out.println(); byte[] byte2 = string.getBytes("utf-16be"); //java平台采用的双字节编码,全是占两个字节 for (byte b : byte2) { System.out.print(Integer.toHexString(b & 0xff) + " "); } System.out.println(); byte[] byte3 = string.getBytes("gbk"); //gbk编码中汉字占两个字节 for (byte b : byte3) { System.out.print(Integer.toHexString(b & 0xff) + " "); } //二进制转换成字符串要采用相同的编码,否则会出现乱码 System.out.println("\n" + new String(byte1,"gbk")); System.out.println(new String(byte1,"utf-8")); } }
相关文章推荐
- 【mybatis源码分析】原理分析之二:框架整体设计
- DateTime.ToString()的各种日期格式及互转
- Android系统服务-WindowManager
- Android 70道面试题汇总不再愁面试
- C++常用的字符串处理函数-全
- .h和.cpp文件的区别
- Android中AppCompat和Holo的一个问题
- Etcd学习(二)集群搭建Clustering
- 数据可视化指南(干货)
- “Hello World” 这个程序的起源与历史
- iOS自定义弹窗(UIView)
- LOB segment corruption
- web前端之css_day1
- java代码工具--Date格式化
- 【mybatis源码分析】原理分析之一:从JDBC到Mybatis
- pdo_mysql 安装
- Linux软连接和硬链接
- 寄云-Paas云服务体验
- 寄云-Paas云服务体验
- 寄云-Paas云服务体验