2

I am writing very simple console application in Java.

The problem is that I need to ouput cyrillic and estonian non-utf8 symbols to console, but in Windows I get bunch of strange symbols and in MacOsX I get only ???? instead of something more readable.

How Can I achieve my aim?

--UPDATE 1--

locale gave me:

LANG=
LC_COLLATE="C"
LC_CTYPE="UTF-8"
LC_MESSAGES="C"
LC_MONETARY="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_ALL=

Seems I am stuck with that UTF-8 thing %)

Strange idea:

Is there any way to get a console from eclipse and use it outside of eclipse?

Jevgeni Smirnov
  • 3,787
  • 5
  • 33
  • 50
  • 1
    First thought: use a font that supports those particular unicode values – mre Mar 22 '12 at 12:15
  • Is it possible to set a font for System.out.println()? – Jevgeni Smirnov Mar 22 '12 at 12:21
  • Windows DOS command prompt is a non-Unicode program: it only supports certain fonts (right-click on top-left icon to access its properties) and it depends on your current language setting. You don't have much choice under Windows other than to modify the current **Language for non-Unicode programs** to the language you want but this is a global setting which you need to restart http://technet.microsoft.com/en-us/library/cc721887(WS.10).aspx – ecle Mar 22 '12 at 14:03
  • For MacOSX i8n support: http://www.rift.dk/news.php?item.7.6 (retrieved 2006) and http://stackoverflow.com/questions/4606570/os-x-terminal-utf-8-issues – ecle Mar 22 '12 at 15:43
  • Do you use precompiled classes on Mac or do you compile from source? If you compile from source, what is the character encoding of the source files? `javac` will assume it's the system default encoding, utf-8. If it's something different you have to use the `-encoding` parameter. Otherwise the compiler can't know what characters your source files have. – Joni Mar 23 '12 at 07:29

1 Answers1

1

Windows Terminal: The terminal program, cmd.exe, doesn't use the same encoding as the rest of the OS, and from Java you have no way of knowing if you are being run from a terminal or not. You have to set the font used by cmd.exe to Lucida Console and switch the "code page" with chcp before running the program:

OS X Terminal: as far as I know the terminal is configured for UTF-8, so you can just use UTF-8. Use the locale command to check your encoding.

Joni
  • 108,737
  • 14
  • 143
  • 193
  • Ok Thanks. At least I know what's going on. Also check the update please. – Jevgeni Smirnov Mar 22 '12 at 14:17
  • **chcp** works fine for code pages with single-byte character sets like Windows-1251 and Windows-1257. But, for double-byte character sets like CJK Unified Ideographs, you still need to install its multilingual language pack to set the system code page for the particular language. Otherwise, it will return **Invalid code page** error. – ecle Mar 22 '12 at 14:47