如图,java中同样是utf-8存储的字符串,为什么这两种方式输出的字节会不同?

 平凡特产小店 发布于 2022-10-25 05:11
  • php
  • 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()

      2022-10-26 14:17 回答
    • 首先确保编码统一,文件编码UTF-8,以UTF-8去读文件,getBytes也传入UTF-8
      另,不要用记事本!不要用记事本!不要用记事本!重要的事情说三遍!!!

      2022-10-26 14:18 回答
    撰写答案
    今天,你开发时遇到什么问题呢?
    立即提问
    热门标签
    PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
    Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有