大家讲道理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 require be used when more control over the encoding process is required.
傳送門:String.getBytes()