文章详情页
如图,java中同样是utf-8存储的字符串,为什么这两种方式输出的字节会不同?
问题描述
问题解答
回答1:首先确保编码统一,文件编码UTF-8,以UTF-8去读文件,getBytes也传入UTF-8另,不要用记事本!不要用记事本!不要用记事本!重要的事情说三遍!!!
回答2:在 Java8 的文档中说 String.getBytes() 是按平台默认的字符集来编码。如果是 Windows,默认字符集不是 utf-8,而是 gbk。Linux 要看配置(具体如何我不是很清楚)。
Encodes this String into a sequence of bytes using the platform’s default charset, storing the result into a new byte array.
The behavior of this method when this string cannot be encoded in the default charset is unspecified. The CharsetEncoder class should be used when more control over the encoding process is required.
传送门:String.getBytes()
标签:
java
相关文章:
1. javascript - 百度搜索网站,如何让搜索结果显示一张图片加上一段描述,如图;求教2. javascript - vue 数据更新了。但是dom没有更新,,,,,如图3. css3 怎么实现锯齿状的剪纸效果(如图)4. 关于mysql unique的问题,如图所示5. css3里rotate怎么实现如图的效果6. javascript - 如图,百度首页,查看源代码为什么什么都没有?7. java - 如图,同样一个表单,为什么用myeclipse内置的浏览器提交就会自动编码,用chrome浏览器就不会自动编码?8. html - 前端大牛都顶一下!CSS鼠标样式问题,如图所示9. MySQL主键冲突时的更新操作和替换操作在功能上有什么差别(如图)10. centos - node-sass,唉,如图。
排行榜