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

PHP中文网
PHP中文网

认证高级PHP讲师

全部回覆(2)
大家讲道理

先確保編碼統一,文件編碼UTF-8,以UTF-8去读文件,getBytes也传入UTF-8
另,不要用記事本!不要用記事本!不要用記事本!重要的事情說三遍! ! !

迷茫

在 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()

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!