Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 978
goh Avatar asked Sep 15 '26 09:09

goh


1 Answers

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.

like image 72
McDowell Avatar answered Sep 17 '26 21:09

McDowell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!