2 Replies Latest reply: Jun 3, 2010 1:54 AM by 843810 RSS

    Showing UNICODE characters in DOS Console.

    843810
      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';
      System.out.println(var1);
      System.out.println(var2);
      System.out.println(var3);

      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.
          843810
          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.
            843810
            Sorry, I didn't get the idea...
            Do you mean anything like this?

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

            It still not working.

            I also tried this piece of code:

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

            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.