Does the Scala compiler work with UTF-8 encoded source files?

后端 未结 3 2077
星月不相逢
星月不相逢 2020-12-19 20:45

I have a very simple bit of Scala code

 var str = \"≤\"
 for( ch <- str ) { printf(\"%d, %x\", ch.toInt, ch.toInt) ; println  }
 println
 str = \"\\u2264         


        
3条回答
  •  一生所求
    2020-12-19 21:24

    Yes Scala fully supports UTF-8.

    I can't reproduce your results. MacOS X, Java 7, Scala 2.10.4.

    Check the file encoding of your system:

    scala> System.getProperty("file.encoding")
    res0: String = UTF-8
    

    Add this line to your .bashrc . This might fix the problem in some *nix environments.

    export JAVA_OPTS='-Dfile.encoding=UTF-8'
    

    Sometimes the IDE is set to the wrong file encoding. You could check this also.

提交回复
热议问题