J'utilise java io pour extraire du texte d'un serveur qui pourrait produire un caractère tel que é. puis l'affiche en utilisant System.err, ils se révèlent être '?'. J'utilise l'encodage UTF8. Qu'est-ce qui ne va pas? int len = 0;lecture unicode
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: juste essayé le code suivant:
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);
est sorti pour être indésirable ainsi:
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¥???
Code Reformaté; s'il vous plaît revenir si incorrect. – trashgod
Bien que non lié au problème, 'StringBuilder' est préféré dans cette utilisation. – trashgod