L
L
Loligan2016-03-01 19:20:18
Java
Loligan, 2016-03-01 19:20:18

Why, when receiving the URL of the page through the InputStream, instead of Russian characters, krakazables are obtained?

I'm trying to get HTML, but instead of Russian characters I get some kind of bugs. Help solve the problem.

public class ParsingDownload {
public static void PageDownload() throws MalformedURLException {
URL url = new URL(" yandex.ru ");
try {
InputStream page = url.openStream();
while (true) {
int oneByte = page.read();
if (oneByte != -1) {
System.out.printf(String.valueOf((char) oneByte));
} else {
break;
}
}
} catch (Exception e) {
System. out. println("lol");
}
}
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MamOn, 2016-03-01
@MamOn

See an example here: https://docs.oracle.com/javase/tutorial/networking...
Only in the InputStreamReader constructor, substitute the desired encoding.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question