Remember the post Why I (rarely) Hate Java? Well, this is another of those moments. I was trying to output a string encoded in UTF8 and it was displaying as ??? So, how am I supposed to fix this?
Well, I think, when Java started off, the designers perhaps didn’t bother about encoding. That’s why you see Streams initially in the java.io package and then the readers and writers. The later are aware of encoding while the former classes are not. And unfortunately, the System.in and system.out happen to be the stream classes. As a result, it’s not possible to do utf8 or other non-default encodings.
So, the way to fix this is
PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
Now, this should work just fine. And BTW, if you are trying to see the output in a linux console or using vi editor, you would still see the data as some garbage. One option is to open it in Firefox and make sure that the character encoding is in utf8.