问题
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?
回答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:
- Cyrillic: use chcp 1251
- Estonian: probably you need chcp 1257
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.
来源:https://stackoverflow.com/questions/9822039/output-non-utf8-symbols-to-console