2 Replies Latest reply on Jun 3, 2010 6:54 AM by 843810

    Showing UNICODE characters in DOS Console.

      Have you been able to show UNICODE characters (not existing in ASCII) in DOS Console?

      Basically, I am trying following code snippet to show three Greek characters:

      char var1 = '\u03B1';
      char var2 = '\u03B2';
      char var3 = '\u03B3';

      I am near to get it following these steps, but it doesn't work completely because after each character it shows garbage chars:

      1.- Change DOS Console font to Lucida Console.
      2.- Change DOS Console encoding to UNICODE executing following command: chcp 65001
      3.- Add following JVM argument when executing the test: -Dfile.encoding=UTF-8

      Any help?
      Thanks in advance.
        • 1. Re: Showing UNICODE characters in DOS Console.
          Windows Console does not support UTF-8 at all - meaning that you will not be able to see Unicode on the console if you output it as UTF-8. You can get Unicode support only using UTF-16.

          The reason is because 65001 is not valid codepage, it's only used for converting but you cannot set it as active codepage (not even on Windows 7).

          This is creating other problems because if you redirect the output to different files you may get inconsistent encoding.

          In order to prevent this kind of inconsistencies you may want to output as UTF-16 only to console (no stdout/stderr redirection) and use UTF-8 if redirected.
          • 2. Re: Showing UNICODE characters in DOS Console.
            Sorry, I didn't get the idea...
            Do you mean anything like this?

                           PrintStream ps = new PrintStream(System.out, true, "UTF-8");
                           char var1 = '\u03B1';
                           char var2 = '\u03B2';
                           char var3 = '\u03B3';
                      catch (UnsupportedEncodingException e)

            It still not working.

            I also tried this piece of code:

            char var1 = '\u03B1';
                      char var2 = '\u03B2';
                      char var3 = '\u03B3';
            Console con = System.console();

            But it just works for the first character. Does it make sense? Lucida Console font has all of those characters implemented.
            Another problem with this last solution is that print() doesn't print anything. I have to use println().

            Any comment and advice for both samples?
            Thanks again.