Heim > Fragen und Antworten > Hauptteil
大家讲道理2017-04-18 10:50:35
首先确保编码统一,文件编码UTF-8
,以UTF-8
去读文件,getBytes
也传入UTF-8
另,不要用记事本!不要用记事本!不要用记事本!重要的事情说三遍!!!
迷茫2017-04-18 10:50:35
在 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()