我正在尝试从 URL 读取内容,但它确实返回了奇怪的符号而不是“è”、“à”等。
这是我正在使用的代码:
public static String getPageContent(String _url) {
URL url;
InputStream is = null;
BufferedReader dis;
String line;
String text = "";
try {
url = new URL(_url);
is = url.openStream();
//This line should open the stream as UTF-8
dis = new BufferedReader(new InputStreamReader(is, "UTF-8"));
while ((line = dis.readLine()) != null) {
text += line + "\n";
}
} catch (MalformedURLException mue) {
mue.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
} finally {
try {
is.close();
} catch (IOException ioe) {
// nothing to see here
}
}
return text;
}
我看到了其他类似的问题,所有问题的回答都像
Declare your inputstream as
new InputStreamReader(is, "UTF-8")
但我无法让它工作。
例如,如果我的 url 内容包含
è uno dei più
我明白了
è uno dei più
我错过了什么?