if i print unicode String like ελληνικά on the console using the print
method of System.out
stream, its printed as expected (As i use Ubuntu mono in my output console which supports UTF characters).
But if i try to read from the console unicode characters with UTF-8 encoding using System.in stream, it doesn't read properly. I have tried many different ways to achieve it using various reader classes with the System.in stream but it never works. So does anyone know a way i could do that
Here is a sample of code
BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in, "UTF-8"));
BufferedWriter console = new BufferedWriter(new OutputStreamWriter(System.out, "UTF-8"));
console.write("p1: Γίνεται πάντως\n");
console.flush();
System.out.println("p2: Γίνεται πάντως");
byte dataBytes[] = keyboard.readLine().getBytes(Charset.forName("UTF-8"));
System.out.println("p3: " + new String(dataBytes));
console.write("p4: " + new String(dataBytes, "UTF-8") + "\n");
console.flush();
Scanner scan = new Scanner(System.in, "UTF-8");
System.out.println("p5: " + (char) System.in.read());
System.out.println("p6: " + scan.nextLine());
System.out.println("p7: " + keyboard.readLine());
and the output on my console:
p1: Γίνεται πάντως
p2: Γίνεται πάντως
Δέν
p3: ���
p4: ���
Δέν
p5: Ä
p6: ��
Δέν
p7: ���
my IDE is Netbeans