文章詳情頁
如圖,java中同樣是utf-8存儲的字符串,為什么這兩種方式輸出的字節會不同?
瀏覽:151日期:2024-02-04 17:10:08
問題描述
問題解答
回答1:首先確保編碼統一,文件編碼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
相關文章:
1. java - 如圖,a.txt文件開頭什么都沒有,FileInputstream讀取的時候為什么還會出現亂碼?2. css3里rotate怎么實現如圖的效果3. javascript - jquery怎么給select option一個點擊時觸發的事件,如圖 如果選擇自定義觸發一個時間?4. css3 - 如圖的flex骰子布局是怎么實現的?5. 關于mysql unique的問題,如圖所示6. java - 如圖代碼,Collection 類中的iterator()是抽象方法,為什么可以調用?7. 怎么php怎么通過數組顯示sql查詢結果呢,查詢結果有多條,如圖。我要forsearch里面echo8. javascript - angular使從elastichearch中取出的文本高亮顯示,如圖所示9. javascript - 如圖,百度首頁,查看源代碼為什么什么都沒有?10. MySQL主鍵沖突時的更新操作和替換操作在功能上有什么差別(如圖)
排行榜
