Character Encoding
Default Encoding
The default character encoding is ISO-8859-1
. It is thus the encoding used when:
creating a new string from a byte array without specifying the encoding (String(byte[]) constructor),
getting the byte array from a string without specifying the encoding (String.getBytes() method),
printing a string to standard output stream (System.out),
creating a new PrintStream without specifying the encoding.
UTF-8 Encoding
EDC provides an implementation of the UTF-8
character encoding.
It can be embedded using the Embed UTF-8 encoding option (otherwise a java.io.UnsupportedEncodingException exception will be thrown).
This implementation also supports Unicode code points as supplementary characters, by setting the constant com.microej.library.edc.supplementarycharacter.enabled
to true
.
Custom Encoding
It is possible to connect additional custom encodings. Please contact our support team for more details.
Console Output
By default, the standard output stream (System.out) uses ISO-8859-1
encoding to print strings. If you want to print a string with a different encoding, you can create a new PrintStream:
PrintStream outUtf8 = new PrintStream(System.out, true, "UTF-8");
outUtf8.println("你好");
Warning
Make sure you embed the UTF-8
encoder (see UTF-8 Encoding)
The print methods write the raw byte array with the encoding used by the PrintStream to the console. The console must then be configured with the same encoding to display characters properly.
Set Encoding in MicroEJ SDK Console
The default encoding for Eclipse consoles is UTF-8
. If your application prints non-ASCII characters, they may not be displayed properly.
The encoding used by a console for a given application can be set in the application launcher options: Run > Run Configurations…, and then Common tab > Encoding radio buttons.