I'm downloading an HTML file and I need to display it with System.out.println()
.
The problem is that instead of Greek characters I get rubbish.
I'm using to download the code below to download the HTML file:
URL url = new URL("here goes the link to the html file");
BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
String htmlfile = "";
String temp;
while ((temp = br.readLine()) != null) {
htmlfile+= temp;
}
System.out.println(htmlfile);
Is it possible to fix this problem? Here is a sample of what I get as a result:
<title>Ξ Ολη ΞλΡκΟΟΏΟ ΟΏ δικΟΟΞ±ΞΊΟ ΟΟΟΞΏ</title>
All my regional settings on my computer are fine. I can use System.out.println
to display Greek words directly.
I have a feeling I need to change some locale settings in the BufferedReader
but I'm not sure how to do it, or whether that's the correct way of approaching this problem.
Somewhat off topic, I have a feeling the above method of downloading the HTML file is really ineffective. For example, when I use html+=temp
, aren't I basically creating a new String
instance every time I read a line from the HTML file? This sounds very costly, if you can please suggest me other methods of doing the same thing that is more effective.