How can you display UTF-8 characters in the Console tab?

Hi -

For a quick-n-dirty test I am printing out a utf-8 string using System.out.println(). This is on a Windows Vista (USA) system using JDK 1.6.0_07. The String is constructed with a byte[] of UTF-8 encoded bytes using, eg. String myUTF8String = new String(myByteBuffer, "UTF-8"). The IDEA console tab contains gibberish characters for high order characters such as Arabic ones, example: 'سموالشيخ' instead of the actual Arabic ones. I know my byte array is correct because if I send it to a file (using -Dfile.encoding=UTF-8 as a VM parameter) I get the correct characters. Also, if I examine myUTF8String in the IDEA Debugger tab I see the correct Arabic characters. My understanding is that System.out.println() uses the default system encoding, which for Windows is not UTF-8. Assuming this is the issue with the Console tab I tried:

OutputStreamWriter nosw = new OutputStreamWriter(System.out,"UTF-8");
nosw.write(myUTF8String );
nosw.flush();

but this yielded the same results. Any pointers on this would be appreciated.

TIA

-NBW

4 comments
Comment actions Permalink

I've found a solution.
The point is that run/debug console uses the IDEA encoding. IDEA is a java application and encoding can be set in the idea.exe.vmoptions file as ordinary VM parameter. This file lies near your IDEA executabe file and conteins a set of JVM parameters. Add -Dfile.encoding=UTF-8 there to set encoding in UTF-8.

An application or a junit test has to be run with the same encoding as IDEA does. Encoding for the application can be set in "Run/Debug Configuration" window in the "VM parametrs:" "-Dfile.encoding=UTF-8" string makes UTF-8 default encoding for the app.



4
Comment actions Permalink

Still hoping for some insight on this one.  The console tab is using the system file encoding, in my case WINDOWS-1252.  Is there perhaps a property I can set in IDEAs properties file to set the file encoding for the ConsoleWindow?

Also, on a similar note, When I use JDBC Console I see its cmd line is setting -Dfile.encoding=windows-1252.  Is there a properties or project preference that controls this?

Thanks!

1
Comment actions Permalink

Past this code at the beginning of html code:

<?xml version="1.0" encoding="UTF-8"?>
0
Comment actions Permalink

Note, that if you're using 64 bit IDEA, you need to edit the file idea64.exe.vmoptions.

0

Please sign in to leave a comment.