Printing Unicode Characters

488 views
Skip to first unread message

Bruno

unread,
Jun 16, 2012, 2:30:32 AM6/16/12
to scala...@googlegroups.com
Hi,

When I try to println unicode characters  (e.g. println("\u2200")), a question mark ("?") is displayed instead.

If I call:

System.getProperty("file.encoding")

I get:

"MacRoman"

(I'm running my application in a Mac, in the terminal and via SBT).

I tried to set the file encoding to UTF-8:

System.setProperty("file.encoding", "UTF-8")

But I still see only question marks.

Does anyone know what I should do to correctly println unicode characters?

Best regards,

Bruno

Paul Butcher

unread,
Jun 16, 2012, 4:17:22 AM6/16/12
to Bruno, scala...@googlegroups.com
Yeah this is a massive pain in the backside :-( It's primarily a Java problem - Java seems determined to be stuck in the 1990s when it comes to character encoding.

For a solution, see:


or


--
paul.butcher->msgCount++

Snetterton, Castle Combe, Cadwell Park...
Who says I have a one track mind?

http://www.paulbutcher.com/
LinkedIn: http://www.linkedin.com/in/paulbutcher
MSN: pa...@paulbutcher.com
AIM: paulrabutcher
Skype: paulrabutcher

Simon Ochsenreither

unread,
Jun 16, 2012, 5:14:54 PM6/16/12
to scala...@googlegroups.com, Bruno
Isn't that solely a platform problem? As far as I know Java picks up the encoding of the host system. I agree that running on unmaintained/niche systems with old/deprecated defaults can be a bit annoying because of that.

Paul Butcher

unread,
Jun 16, 2012, 5:27:02 PM6/16/12
to Simon Ochsenreither, scala...@googlegroups.com, Bruno

On Saturday, 16 June 2012 at 22:14, Simon Ochsenreither wrote:

Isn't that solely a platform problem? As far as I know Java picks up the encoding of the host system. I agree that running on unmaintained/niche systems with old/deprecated defaults can be a bit annoying because of that.

I don't believe that it is, no. I certainly have the same problem on my MacBook Pro running Lion, which is hardly an unmaintained or niche system. There was a long discussion about this on scala-internals some while ago:


I'm not aware of anything having changed or improved since then (although I would be delighted to be disabused of this misconception if it is a misconception).

Jason Zaugg

unread,
Jun 16, 2012, 5:47:04 PM6/16/12
to Paul Butcher, Simon Ochsenreither, scala...@googlegroups.com, Bruno
On Sat, Jun 16, 2012 at 11:27 PM, Paul Butcher <pa...@paulbutcher.com> wrote:
> On Saturday, 16 June 2012 at 22:14, Simon Ochsenreither wrote:
>
> Isn't that solely a platform problem? As far as I know Java picks up the
> encoding of the host system. I agree that running on unmaintained/niche
> systems with old/deprecated defaults can be a bit annoying because of that.
>
>
> I don't believe that it is, no. I certainly have the same problem on my
> MacBook Pro running Lion, which is hardly an unmaintained or niche system.
> There was a long discussion about this on scala-internals some while ago:
>
> http://thread.gmane.org/gmane.comp.lang.scala.internals/189
>
> I'm not aware of anything having changed or improved since then (although I
> would be delighted to be disabused of this misconception if it is a
> misconception).

The snowman works for me:

http://dl.dropbox.com/u/106552/Screen%20Shot%202012-06-16%20at%2011.44.56%20PM.png

-jason

Paul Butcher

unread,
Jun 16, 2012, 8:22:13 PM6/16/12
to Jason Zaugg, Simon Ochsenreither, scala...@googlegroups.com, Bruno
Hmm - so what's different between your setup and mine?


--
paul.butcher->msgCount++

Snetterton, Castle Combe, Cadwell Park...
Who says I have a one track mind?

http://www.paulbutcher.com/
LinkedIn: http://www.linkedin.com/in/paulbutcher
MSN: pa...@paulbutcher.com
AIM: paulrabutcher
Skype: paulrabutcher

Bruno Woltzenlogel Paleo

unread,
Jun 17, 2012, 3:39:41 AM6/17/12
to Paul Butcher, Jason Zaugg, Simon Ochsenreither, scala...@googlegroups.com
Thanks, Paul, Jason and Simon, for your answers.

I'm now using a solution that is a slight variant of the solution cited by Paul in http://2012.8-p.info/english/2/16/scala .
The difference is that I set JAVA_TOOL_OPTIONS='-Dfile.encoding=UTF-8' in my "~/.MacOSX/environment.plist" file.

I'm also curious to know what makes Simon's setup work apparently without having to set the JAVA_TOOL_OPTIONS variable.

I agree with Jason that this is mostly Apple's fault. They could have made our life easier if they had used something more standard than MacRoman as the system's default encoding.

Best regards!

Bruno
Reply all
Reply to author
Forward
0 new messages