Print special chars in Java
I am testing java strings using German chars, but while asking it to print it returns some other chars. Any help is appreciated.
The output I am getting: õõõõ
Note the difference. Any experienced Java tester may please help.
Re: Print special chars in Java
The command chcp will tell you ( and allow you to change ) the encoding used by the command prompt. You will probably find that it is cp437.
The encoding System.out uses is determined at JVM startup and is the default encoding for the current platform. You can find out what it is on your system by querying an OutputStreamWriter that has been constructed to use the default encoding:
1: OutputStreamWriter osw = new OutputStreamWriter(System.out);
To get chars to render as intended on the command prompt you could write them out using an OutputStreamWriter constructed to use the cp437 encoding:
1: OutputStreamWriter osw = new OutputStreamWriter(System.out,"cp43+
2: PrintWriter pw = new PrintWriter(osw);
3: pw.println("YOUR CHARS");