Issues with strings and special characters

Hi,

I have trouble when working with strings including special characters.

For example this code:

	public static void main(String[] args) {
		System.out.println("Hello World!"); //$NON-NLS-1$
		System.out.println("Привет мир"); //$NON-NLS-1$
	}

Will display this in the console:

=============== [ Initialization Stage ] ===============
=============== [ Launching on Simulator ] ===============
Hello World!
@825B <8@
=============== [ Completed Successfully ] ===============

SUCCESS

Running this as a Java application will display this:

Hello World!
Привет мир

What is the difference with a MicroEJ application ?

Regards,

Philip

Hi Philip,

The implementation of the print method on the standard output (System.out) is based on the default encoding, which is ISO-8859-1 on MicroEJ whereas it is usually UTF-8 on JavaSE.

So far there is no way to modify the default encoding of System.out PrintStream implementation, so if you have to deal with Unicode characters on the standard output stream, I suggest the following snippet to convert the standard output to an UTF-8 PrintStream:

		PrintStream outUTF8 = new PrintStream(System.out, true, "UTF-8");
		outUTF8.println("Привет мир");

In addition, we can mention that characters are successfully printed in MicroEJ SDK because the Eclipse console is configured by default for UTF-8 decoding:
See a MicroEJ Application launch configuration > Common tab > Encoding options:
image