Java charset - How to correctly read from System.in?

0

I am creating an application to exchange messages between computers using Sockets, through the cmd or terminal (I want it to run in linux and windows, console application).

But I'm having trouble coding. When I read an entry through System.in, in the Windows 7 console, the output is buggy. With the following code:

Scanner s = new Scanner(System.in);
System.out.println(s.nextLine());

The accented or special characters are not displayed correctly.

I'm using the following code to pass messages:

Main.CHARSET = "UTF-8"

Scanner teclado = new Scanner(System.in,Main.CHARSET);
BufferedWriter saida = new BufferedWriter(new OutputStreamWriter(new BufferedOutputStream(cliente.getOutputStream()),Main.CHARSET)));
saida.write(nick + " conectado!");
saida.flush();
while (teclado.hasNextLine()) {
    saida.write(nick +": "+ s);
    saida.flush();
}

And to receive:

BufferedReader br = new BufferedReader(new InputStreamReader(servidor,Main.CHARSET)));
String s;
while ((s = br.readLine()) != null) {
    System.out.println(s);
}

The question is, how to read correctly from the console and transmit so that the other user receives and is able to view on your console?

    
asked by anonymous 06.01.2016 / 22:00

0 answers