I’m using Google App Engine to fetch some data. Before sending the data from GAE, I set the content type to “text/html” and the character encoding to “UTF-8”. I’m certain that the characters åöä are stored correctly on the server database.
When getting the data from my android app, everything works fine. The characters åäö are represented correctly. Here’s the strange part: when getting the same data from my java app on windows, åäö gets replaced by “Ã¥” and other strange symbols. When getting the same data from my java app on a mac, åäö gets replaced by some other strange characters.
So my question is: Why does the android app read the string correctly while the java app doesn’t?
EDIT:
Here’s how I send the string from GAE:
resp.setContentType("text/html");
resp.setCharacterEncoding("UTF-8");
resp.getWriter().println(myString);
Here’s how I read it in java both on android and windows:
String response = "";
try {
URL url = new URL("http://mydomain.com/blabla");
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
response += line;
}
wr.close();
rd.close();
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Response is: " + response);
How do you know the data is wrong on Windows and the Mac? Are you printing it out to, say, a console? If so, it’s likely (especially on Windows) that the console character encoding is wrong. You’ll be writing UTF-8 encoded characters to the console which will be trying to interpret them as Windows CP-whatever.