1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| byte[] buffer = new byte[512]; // à toi de voir la taille
String charset1, charset2, str;
StringBuilder text;
PushBackInputStream in;
int index;
text = new StringBuilder();
do {
text.append(str);
in.read(buffer, 0, buffer.size);
str = new String(buffer, charset1);
index = str.indexOf("\n");
} while ( index == -1);
index ++; // ça sert à inclure le \n dans le premier charset
text.append(str.substring(0, index));
//on récupère la fin du tableau dans le second charset
in.unread(buffer, index, buffer.size - index);
str = new String(buffer, index, buffer.size - index, charset2);
text.append(str);
// on lit tout le reste sous le second charset
while(in.available != 0) {
in.read(buffer, 0, buffer.size);
str = new String(buffer, charset2);
text.append(str);
}
System.out.println(text.toString()); |
Partager