简体   繁体   中英

Whats wrong with Scala encoding?

I guess something is wrong with Scala while displaying "\\303\\251" unicode. Ideally it should display "é" but instead it is displaying "é".

I tried with several scala versions like 2.10.4, 2.10.5 & 2.11.8 but i got the same output (ie, é).

$ JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF8 sbt
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF8
> console
Welcome to Scala version 2.11.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_71).
scala> print ("\303\251")
é
scala> System.getProperty("file.encoding");
res2: String = UTF8

even i used equivalent hex escape literals for \\303\\251 ie, \Ã\©, still the same output

scala> print ("\u00c3\u00a9")
é

Note: I face this issue only in Linux and Ubuntu OS but in MAC it works very fine as shown below:

scala> print ("\303\251")
é

I didn't understand why scala is giving wrong output in linux & ubuntu machines. Does anyone faced this issue? Please let me know how to fix this. Thanks for your time and help.

Yes, Linux character encoding is the issue. After changing the environment variable LANG (as shown below), everything works properly.

/usr/bin/env LANG=en_US.UTF-8 /usr/bin/xterm

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM