Próbuję pobrać dane z http://api.freebase.com/api/trans/raw/m/0h47Java kodowania UTF-8 nie jest ustawiony na URLConnection
Jak widać w tekście są śpiewa tak: /ælˈdʒɪəriə/
.
Kiedy próbuję dostać źródła ze strony otrzymuję tekst z śpiewa jak ú
itp
Do tej pory próbowałem z następującego kodu:
urlConnection.setRequestProperty("Accept-Charset", "UTF-8");
urlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
Co robię źle?
Cały mój kod:
URL url = null;
URLConnection urlConn = null;
DataInputStream input = null;
try {
url = new URL("http://api.freebase.com/api/trans/raw/m/0h47");
} catch (MalformedURLException e) {e.printStackTrace();}
try {
urlConn = url.openConnection();
} catch (IOException e) { e.printStackTrace(); }
urlConn.setRequestProperty("Accept-Charset", "UTF-8");
urlConn.setRequestProperty("Content-Type", "text/plain; charset=utf-8");
urlConn.setDoInput(true);
urlConn.setUseCaches(false);
StringBuffer strBseznam = new StringBuffer();
if (strBseznam.length() > 0)
strBseznam.deleteCharAt(strBseznam.length() - 1);
try {
input = new DataInputStream(urlConn.getInputStream());
} catch (IOException e) { e.printStackTrace(); }
String str = "";
StringBuffer strB = new StringBuffer();
strB.setLength(0);
try {
while (null != ((str = input.readLine())))
{
strB.append(str);
}
input.close();
} catch (IOException e) { e.printStackTrace(); }
Wydaje się, że jedyną rzeczą, która zadziała. Dziękuję Ci. – Ales
Mam ten sam problem, proszę o pomoc. m.appendTail (m); ta linia mnie błąd. –
@ ersyn61: Przepraszam, poprawiono; powinno być 'm.appendTail (sb);'. –