某些页面的内容中包含HTML特殊字符,但它们显示为方块(未知字符)。下载页面中的HTML字符不能正确显示
我该怎么办?
我可以将包含carachters的字符串转换为另一种格式(UTF-8)吗?它发生在从InputStream到String的转换中。我真的不知道是什么原因造成的。
public HttpURLConnection openConnection(String url) {
try {
URL urlDownload = new URL(url);
HttpURLConnection con = (HttpURLConnection) urlDownload.openConnection();
con.setInstanceFollowRedirects(true);
con.connect();
return con;
} catch (Exception e) {
return null;
}
}
private String getContent(HttpURLConnection con) {
try {
return IOUtils.toString(con.getInputStream());
} catch (Exception e) {
System.out.println("Erro baixando página: " + e);
return null;
}
}
page.setContent(getContent(openConnection(con)));
你能否包含你当前的代码? – eggyal 2011-05-07 13:24:45