为什么字符串“¿被翻译成“”当调用.getBytes() [英] Why does the string "¿" get translated to "¿" when calling .getBytes()

查看:133
本文介绍了为什么字符串“¿被翻译成“”当调用.getBytes()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用

System.out.println(new String("¿".getBytes("UTF-8")));

â€而不是只是¿。

为什么?

推荐答案

您不必使用UTF-16来解决这个问题:

You don't have to use UTF-16 to solve this:

new String("¿".getBytes("UTF-8"), "UTF-8");

工作正常。只要给予 getBytes()方法的编码与传递给String构造函数的编码相同,就应该可以了!

works just fine. As long as the encoding given to the getBytes() method is the same as the encoding you pass to the String constructor, you should be fine!

这篇关于为什么字符串“¿被翻译成“”当调用.getBytes()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆