我是Scala的新手,想使用scala.io.Source
类。但我发现它使用 Char
s,但不是 Byte
s。我感到困惑的是Char
是编码/平台依赖的。我的意思是我们可以用UTF-8
或"windows-1251"编码字符。
windows-1251
是严格的 1 字节编码...有没有办法使用原始字节进行操作?
如果你想
把Char
读成windows-1251
,你可以这样做:
scala.io.Source.fromFile(myFile, "windows-1251")
为此读取设置编码。