1

Possible Duplicate:
How to Force a jar to uses(or the jvm runs in) utf-8 instead of the system's default encoding

I have a bunch of Strings that I want to read in as UTF-8. Is there a way to force this encoding in Scala, without passing a command-line parameter?

For example, I want to do something like val utf8EncodedString = new String(myString, "UTF-8").

4

1 回答 1

7

字符串在 Scala/Java 中没有编码。在内部,它们总是保存为 UTF-16,但是当你使用它们时这并不重要。编码和解码发生在 IO 类中。您应该查看scala.io.Source对象的文档,其中包含用于创建Sources 的工厂方法,这些方法将编码作为参数。

于 2012-10-02T21:13:01.310 回答