input/output problem with arabic characters
J'ai écrit le programme suivant :
Code:
1 2 3 4 5 6 7 8 9
| public class Voielle {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("");
System.out.println("entrer la chaine de characteres :");
String mot1 = Clavier.lireLigne();
System.out.println(mot1);
}
} |
J'ai sauvegarder le fichier Voielle.java en UTF-8.
La classe Voielle utilise la classe Clavier décrite dans Clavier.java comme suit :
Code:
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
| import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.StringTokenizer;
public final class Clavier {
private static BufferedReader bufIn = null;
private static StringTokenizer st = null;
private Clavier() {}
private static void initialise() {
if (bufIn == null)
bufIn= new BufferedReader(new InputStreamReader(System.in));
}
private static void read() {
if (bufIn == null)
initialise();
try {
String s = bufIn.readLine();
st = new StringTokenizer(s);
} catch (IOException e) {
System.err.println("read" + " " + e.getMessage());
System.exit(2);
}
}
private static void flushTotal() {
st = null;
bufIn = null ;
}
private static void flush() {
st = null;
}
public static int lireInt() {
if (st == null)
read();
while (! st.hasMoreTokens())
read();
String ss = st.nextToken();
int i = Integer.parseInt(ss);
return(i);
}
public static long lireLong() {
if (st == null)
read();
while (! st.hasMoreTokens())
read();
String ss = st.nextToken();
long i = Long.parseLong(ss);
return(i);
}
public static float lireFloat() {
if (st == null)
read();
while (! st.hasMoreTokens())
read();
String ss = st.nextToken();
float f = Float.parseFloat(ss);
return(f);
}
public static double lireDouble() {
if (st == null)
read();
while (! st.hasMoreTokens())
read();
String ss = st.nextToken();
double f = Double.parseDouble(ss);
return(f);
}
public static String lireString() {
if (st == null)
read();
while (! st.hasMoreTokens())
read();
return(st.nextToken());
}
public static String lireLigne() {
String s = "" ;
if ((st == null) || (!st.hasMoreTokens()))
{
if(bufIn == null)
initialise() ;
try{
s = bufIn.readLine() ;
} catch (IOException e) {
System.err.println("lireString" + " " + e.getMessage());
System.exit(2); // Une erreur s'est produite, on sort du programme.
}
return s ;
}
else
{
System.out.println("Autre cas") ;
return(st.nextToken(System.getProperty("line.separator")));
}
}
} |
Le problème survient lorsque je tente d'utiliser des caractères arabes. Je reçois en sortie un caractère inconnu.
Comment résoudre ce problème ?