一次熬夜解决的java乱码问题

本文探讨了Java中String类的getBytes方法的工作原理及其潜在的问题。该方法将字符串编码为字节序列,使用平台默认的字符集,并返回字节数组。文章指出在不同环境下可能遇到的字符串长度不匹配问题及解决建议。

在java  API中String有一个方法

public byte[] getBytes()

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.

对这个字符串进行编码为一个字节序列使用平台的默认字符集,结果存储到一个新的字节数组

Returns:
    The resultant byte array

 

整个晚上和客户一直抓包,发现有个字符串的长度不一样,在调用接口的时候,不匹配

解决方案

  慎用该方法

http://www.blogjava.net/baizhihui19870626/articles/388054.html

 

 

IT技术和行业交流群 417691667

 

 

转载于:https://www.cnblogs.com/sun-rain/p/4868726.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值