EricHo EricHo - 4 months ago 32
Java Question

How to grab Chinese characters from HTML code using JAVA inputStream?

I would like to download some data from a website using the following methods.

It has no problem downloading English/number content, but it won't generate the correct Chinese character when I try to grab Chinese content.

String url = "";
URL yahooUrl = new URL(url);
reader = new BufferedReader(new InputStreamReader(yahooUrl.openStream()));
String line ="";
while((line =reader.readLine()) != null){
Pattern p = Pattern.compile(
Pattern.quote("<div class=\"title\"><h2>")+ "(.*?)"
Matcher match = p.matcher(htmlData.toString());
stockName =;

Anyone know how to grab content in other languages from internet using Java inputstream?


In your case you didn't specify the character encoding for InputStreamReader, so the platform's default charset is accepted. To read Chinese characters use the UTF-8 charset:

reader = new BufferedReader(new InputStreamReader(yahooUrl.openStream(), "UTF-8"));