I'm using java io to retrieve text from a server that might output character such as é. then output it using System.err, they turn out to be '?'. I am using UTF8 encoding. what's wrong? int len = 0;
char[] buffer = new char[1024];
OutputStream os = sock.getOutputStream();
InputStream is = sock.getInputStream();
os.write(query.getBytes("UTF8"));//iso8859_1"));
Reader reader = new InputStreamReader(is, Charset.forName("UTF-8"));
do {
len = reader.read(buffer);
if (len > 0) {
if (outstring == null) {
outstring = new StringBuffer();
}
outstring.append(buffer, 0, len);
}
} while (len > 0);
System.err.println(outstring);
Edit: just tried the following code:
StringBuffer b = new StringBuffer();
for (char c = 'a'; c < 'd'; c++) {
b.append(c);
}
b.append('\u00a5'); // Japanese Yen symbol
b.append('\u01FC'); // Roman AE with acute accent
b.append('\u0391'); // GREEK Capital Alpha
b.append('\u03A9'); // GREEK Capital Omega
for (int i = 0; i < b.length(); i++) {
System.out.println("Character #" + i + " is " + b.charAt(i));
}
System.out.println("Accumulated characters are " + b);
came out to be junk as well:
Character #0 is a Character #1 is b Character #2 is c Character #3 is ¥ Character #4 is ? Character #5 is ? Character #6 is ? Accumulated characters are abc¥???