【发布时间】:2016-11-16 21:16:51
【问题描述】:
url 的内容是 UTF-8,但是当我 system.out 字符串时,它不再是 UTF-8。如何转换字符串以使其支持 utf-8?我得到了一些这样的词:
Objectgeörienteerd
我尝试过字节数组、输入流等,但没有奏效。
我的代码:
HttpURLConnection connection = null;
String thatUrl = url[0];
URL urly = new URL(thatUrl);
InputStream is = urly.openStream();
final StringBuffer buffer = new StringBuffer();
int counter;
while ((counter = is.read()) != -1) {
buffer.append((char) counter);
}
【问题讨论】:
-
您可能想要使用 buffer.toString()。您也可以尝试 PrintStream out = new PrintStream(System.out, true, "UTF-8"); out.println(缓冲区);因为它允许设置编码。
-
@JohnMorrison 这些与问题无关。
标签: java string encoding utf-8 character-encoding