文章详情页
如图,java中同样是utf-8存储的字符串,为什么这两种方式输出的字节会不同?
浏览:167日期:2024-02-04 17:10:08
问题描述
问题解答
回答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. 怎么php怎么通过数组显示sql查询结果呢,查询结果有多条,如图。2. javascript - 如何用js或者css3实现元素边框的动态效果,如图?3. 怎么php怎么通过数组显示sql查询结果呢,查询结果有多条,如图。我要forsearch里面echo4. 如图,这两个java面试题的答案都是错误的吧?正确的应该怎么写呢?5. javascript - 项目的公共文件如图片JS等文件放在 云上,webroot只放jsp文件,怎么将静态文件通过配置文件引入,sp求大神指导6. css - 新装的typecho博客程序为啥不能上传附件,比如图片!7. Java IO流-InputStream是抽象类,也能调方法?(如图)8. java - 如图,a.txt文件开头什么都没有,FileInputstream读取的时候为什么还会出现乱码?9. java - 如图,jsp页面的form中的action是怎么映射到这个位置的?为什么不写dynUser就可以映射到save?10. javascript - 请问如图红框内typescript这段代码是什么意思?
排行榜
