Android的转换ISO-8859-2到UTF-8

问题描述:

我下载远程文件的HTML源代码code到字符串变量。 Unfortunetely页是EN codeD通过ISO-8859-2,其中包含来自波兰的字母字符。我怎么能转换这个字符串为UTF-8,这样我就可以显示它的部件TextView的?

I'm downloading HTML source code of remote page into String variable. Unfortunetely the page is encoded via iso-8859-2 and contains characters from polish alphabet. How can I convert this string to utf-8, so I can display it's parts in TextView?

感谢

您应该不需要转换字符串可言,如果你听从内容编码头由Web服务器发送。

You shouldn't need to "convert" the string at all, if you obey the Content-Encoding header sent by the web server.

现在,你可能忽略了头,而从服务器读取响应(一些的BufferedReader到的StringBuffer /生成器循环我假设),试试这个在下载code来代替:

Right now, you probably ignore that header while reading the response from the server (some BufferedReader-to-StringBuffer/Builder loop I assume), try this in your download code instead:

HttpResponse response = ....
String text = EntityUtils.toString(response.getEntity());

EntityUtils 它将自动使用指定的内容编码由服务器

EntityUtils will automagically use the content encoding specified by the server.