I want to get content from website where are used polish letter (eg. ś, ć, ę etc) by opening connection using HttpURLConnection
. I set InputStreamReader
to UTF-8
, but that didn't help.
This is my class responsibled for connection:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
public class MyConnection {
URL url;
HttpURLConnection conn;
public MyConnection()
{
}
public void setConnection(URL url)
{
this.url = url;
}
public void connect() throws IOException {
conn = (HttpURLConnection) url.openConnection();
}
public String getContent() throws IOException
{
String data = "";
String tmp;
BufferedReader rd = new BufferedReader(new InputStreamReader(conn
.getInputStream(), "UTF-8"));
while ((tmp = rd.readLine()) != null) {
data += tmp + "\n";
}
rd.close();
return data;
}
}
On the website it's like that:
270 Słabowski
270 Skubiszyński
270 Orzyłowski
270 Mołdrzyk
270 Łagodzki
270 Lęcznar
but my applications reads it like that:
Skubiszy�ski
Orzy�owski
Mo�drzyk
�agodzki
L�cznar
�
is square(but it's not displayed here)
conn.getContentEncoding()
returns null
In file it looks same like in console
Could you tell me how can i change my code that it will work properly?