Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Print Unicode characters to the Terminal with Java' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Print Unicode characters to the Terminal with Java
Authored by: gidds on Feb 11, '05 08:56:18PM

Yep, just what I was going to say.

Actually, there are several related issues here. (I've been through them coz I keep all my files in CP1252, aka Windows Latin-1.)

The main one is the encoding that the JVM uses for file I/O; as you say, you set this using the -D option to set the 'file.encoding' system property when running Java programs. This will affect all character-based -- FileReaders, FileWriters, &c -- unless they specify an alternate encoding (which isn't a good idea in general). Not FileInputStream &c, though, as they're byte-based.

Second is the encoding in your source code; you set this in the same way with the -D option when compiling. This will affect extended characters in string literals &c.

Third is the encoding used by whatever you edit files with. TextEdit can set this in its preferences, for example. Most command-line tools will use the environment variable LC_CTYPE, but there's a problem with 'vi' (at least in 10.2.8) which ignores it. (I've compiled my own version which sets it properly, by calling setlocale(LC_CTYPE, "") at the start.) If no locale is defined for the encoding you want, it's not hard to define your own using mklocale.

And fourth is the encoding used by the terminal itself. Terminal can set this in its Display preferences; iTerm in its Terminal Profiles. (I have a suspicion that extended characters used to cause occasional crashes in Terminal, but that may not apply to recent versions.)

If any of these differ, it'll cause problems at some point... But if they're all set up correctly, it'll handle extended characters just like 7-bit ones, and you'll never need to worry about the difference!

---
Andy/



[ Reply to This | # ]