goh
goh

Reputation: 29511

java println output encoding on windows

This question originates from a question I asked here. There were suggestions that this may be a Java problem instead so I posted another question.

What determines the output encoding of the system.out.println command? Basically, I'm executing a python program from command prompt, which spawns a child process running java(stanford parser) It takes my input document encoded in UTF-8, processes and println my input in specific formats. Back at the python program, I could not decode the output from stdout with utf-8. This works on OSX so I'm suspecting it could be a console encoding issue.

I have tried setting chcp 65001 and changing the font type but these does not work.

Upvotes: 3

Views: 5211

Answers (1)

McDowell
McDowell

Reputation: 108899

It uses the default encoding which on Windows will be an obsolete "ANSI" encoding. The documented way to change this is "via the operating system" though this is as far as it goes. You can also call System.setOut to provide your own mechanism:

System.setOut(new PrintStream(System.out, true, "UTF-8"));

See here for more depth.

Upvotes: 6

Related Questions