Hello,
Summary
I'd like to choose an output charset in a portable way so that the characters are displayed correctly in every environments.
Details
Under Windows, with the default encoding Java is using (I think it's UTF8), the following code
System.out.println("Carr\u00e9");
does not print properly "carr�". That was expected: my Windows terminals accepts characters in CP850. On an other user's computer, the terminal will be CP1250 or I don't know what. You see the trouble.
A little try
I can do something like
System.setOut(new PrintStream(System.out, true, "CP850"));
System.setErr(new PrintStream(System.err, true, "CP850"));
to switch to the proper encoding. BUT:
1) it does not change the
default encoding (using something else than sysout or syserr will encode with UTF8)
2) it's not portable
Question(s)
Is there some portable way (even ugly such as a switch if(windows) if(linux)) to decide which encoding should be used? That would require questionning the terminal currently being used, so I was thinking about some environment variable which would be set by the terminal...
If not, what is the best strategy to make it work anyway (such as asking the user to use a switch on the command line, declaring an env. variable before launching the program, putting it into a property file, ...)? Any article / reference about that?
Once the destination platform's charset has been chosen, which call should I use to make it the default so that the Java API will use that everywhere needed?
I suppose every java developer in the world has the same problem and I'm very suprised to find no good articles on the subject!
Thank you.
Olivier
Added a "don't run" to the subject because I suspect people think I'm asking a newbie question...
Message was edited by:
OlivierMiR