文章詳情頁
如圖,java中同樣是utf-8存儲的字符串,為什么這兩種方式輸出的字節(jié)會不同?
瀏覽:200日期:2024-02-04 17:10:08
問題描述
問題解答
回答1:首先確保編碼統(tǒng)一,文件編碼UTF-8,以UTF-8去讀文件,getBytes也傳入UTF-8另,不要用記事本!不要用記事本!不要用記事本!重要的事情說三遍!!!
回答2:在 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()
標簽:
java
相關(guān)文章:
1. angular.js - 怎么用Angularjs 來實現(xiàn)如圖2. 全屏顯示 - Android莫名全屏(如圖)?3. 如圖,java在括號中輸入new的時候跟在外面的提示不一樣4. javascript - 如何用js或者css3實現(xiàn)元素邊框的動態(tài)效果,如圖?5. java - 如圖,a.txt文件開頭什么都沒有,F(xiàn)ileInputstream讀取的時候為什么還會出現(xiàn)亂碼?6. java - 如圖,jsp頁面的form中的action是怎么映射到這個位置的?為什么不寫dynUser就可以映射到save?7. 如圖的flex骰子布局是怎么實現(xiàn)的?8. node.js - yo webapp構(gòu)建項目時報錯了,如圖9. MySQL主鍵沖突時的更新操作和替換操作在功能上有什么差別(如圖)10. css - 新裝的typecho博客程序為啥不能上傳附件,比如圖片!
排行榜

熱門標簽