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ù
私は何が欠けていますか?