First of all, make sure the encoding is unified and the file is encodedUTF-8,以UTF-8去读文件,getBytes也传入UTF-8 Also, don’t use Notepad! Don't use Notepad! Don't use notepad! Say important things three times! ! !
It is said in the Java8 documentation that String.getBytes() is encoded according to the platform's default character set. In case of Windows, the default character set is not utf-8, but gbk. Linux depends on the configuration (I don’t know exactly how).
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.
First of all, make sure the encoding is unified and the file is encoded
UTF-8
,以UTF-8
去读文件,getBytes
也传入UTF-8
Also, don’t use Notepad! Don't use Notepad! Don't use notepad! Say important things three times! ! !
It is said in the Java8 documentation that
String.getBytes()
is encoded according to the platform's default character set. In case of Windows, the default character set is not utf-8, but gbk. Linux depends on the configuration (I don’t know exactly how).Portal: String.getBytes()