如图,java中同样是utf-8存储的字符串,为什么这两种方式输出的字节会不同?
PHP中文网
PHP中文网 2017-04-18 10:48:35
0
2
524

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(2)
大家讲道理

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.

Portal: String.getBytes()

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!