scala default encoding in windows shell

2019-08-12 16:20发布

问题:

Beginners question: I'm using scala 2.11.4 on a windows 8 machine in the standard command shell (codepage is 850). If I type "Müller" at the scala-prompt scala>"Müller" res0: String = M?ller

The same happens in my first scala trial program:

import scala.io.StdIn.readLine

object Hello {
    def main(args: Array[String]) {
      val myname=readLine("What is your name?","ISO-8859-1")
      println("Hallo " + myname + "!")
    }
}

Calling it via "scala Hello" yields: What is your name?Müller Hallo M?ller!

I guess println uses a different encoding as a default (The "ISO-8859-1"-part did not change anything, by the way)?

回答1:

scala> System.getProperty("file.encoding")

showed cp1252. So I generated a environment variable (thanx to Martin Sturm) JAVA_OPTS="-Dfile.encoding=CP850" and currently everything works as expected (München ist schön).