Home

Using Hangul in Scala

Using Hangul in Scala

When you use non-ASCII characters in your Scala source files, you may get this error message:

error: IO error while decoding <filename> with UTF-8 
Please try specifying another one using the -encoding option 
one error found 
This happens because the Scala compiler does not know how your file is encoded, and makes the wrong assumption on Microsoft Windows. You can fix this problem by specifying the encoding when you compile a file:
scalac -encoding cp949 sourcefile.scala
This does not seem to work when running a Scala script on Microsoft Windows (on Linux and probably Mac OS X the problem does not exist, as source files are normally encoded in Unicode).

With the correct encoding, you can use Hangul in your comments. In fact, Scala even allows you to use Hangul variable names (most other programming languages, such as C, do not allow this):

scala> val 이름 = "정지원"
이름: java.lang.String = 정지원