1

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)?

Rriskit
  • 495
  • 4
  • 15
  • Did you tried with `UTF-8` encoding? I cannot test, but on Unix machine the default works as expected. – Lomig Mégard Dec 27 '14 at 21:14
  • What does doing `chcp 1252` before firing up the scala repl do? I guess you don't have unicode codepoints enable on the cmd shell – S.R.I Dec 28 '14 at 06:31
  • The Scala repl just uses whatever encoding is available to it when it's fired up - that is to say, it inherits those properties from the existing environment. – S.R.I Dec 28 '14 at 06:31
  • chcp 65001 does not support äüö etc on german keyboard – Rriskit Dec 28 '14 at 20:32
  • @S.R.I in a way you're right: but it does not pick up the console default as I expected, uses java default settings (cp1252 in a windows environment) instead. But thank you, it lead to the right point! – Rriskit Dec 28 '14 at 23:15
  • See my answer for related question: http://stackoverflow.com/a/38490217/3706042 – Dedkov Vadim Jul 20 '16 at 20:29

1 Answers1

0
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).

prayagupa
  • 30,204
  • 14
  • 155
  • 192
Rriskit
  • 495
  • 4
  • 15