java byte数组转string老是中文乱码,怎么解决

 

你好,设置String的编码方式即可,代码如下

buff.append(new String (b,0,len,"utf-8"));

 

您的问题已经有小伙伴解答了,请点击【采纳】按钮,采纳帮您提供解决思路的答案,给回答的人一些鼓励哦~~

ps:开通问答VIP,享受5次/月 有问必答服务,了解详情↓↓↓

【电脑端】戳>>>  https://vip.csdn.net/askvip?utm_source=1146287632
【APP 】  戳>>>  https://mall.csdn.net/item/52471?utm_source=1146287632

可以设置编码方式的。

private String utfToString(byte[] data) {

    String str = null;

     try {
           str = new String(data, "utf-8");
    } catch (UnsupportedEncodingException e) {
    }   

    return str;

 }