scala“错误:解码时出现io错误”“使用utf-8”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1930230/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
scala "error: io error while decoding" "with utf-8"
提问by deepblue
this thing keeps coming up
I checked that all my source files are utf8 encoded, and Im using '-encoding UTF8' flag with both scalac and scala command line tools
any ideas?
这件事不断出现我检查了我的所有源文件都是 utf8 编码的,并且我在 scalac 和 scala 命令行工具中使用了“-encoding UTF8”标志,有
什么想法吗?
thank you
谢谢
回答by Daniel C. Sobral
Just to document this, the problem is that the program was being run like this:
只是为了记录这一点,问题是程序是这样运行的:
scala filename.class
Instead, it should be run like this:
相反,它应该像这样运行:
scala package.hierarchy.Object
Where Objectis the name of an main-containing object that you wish to run.
您希望运行的包含对象Object的名称在哪里main。
回答by user43702
I encountered this problem running sbt "test" with Main.scala, for the indicated reason that it wasn'tsaved in UTF-8. I fixed it by changing Eclipse Main.scala "File / Properties / Text file encoding / Other" to "UTF-8" and saving.
我在使用 Main.scala 运行 sbt "test" 时遇到了这个问题,原因是它没有保存在 UTF-8 中。我通过将 Eclipse Main.scala“文件/属性/文本文件编码/其他”更改为“UTF-8”并保存来修复它。
回答by JAL
I was having this error trying to set a classpath to launch the scala interpreter like scala-2.8 /path/to/jars/*.
我在尝试设置类路径以启动 .scala 解释器时遇到此错误scala-2.8 /path/to/jars/*。
The solutions in this thread Setting multiple jars in java classpathsolved my problem; apparently the interpreter was attempting to open a jar file as if it was a text file containing scala commands.
该线程中的解决方案Setting multiple jars in java classpath解决了我的问题;显然,解释器试图打开一个 jar 文件,就好像它是一个包含 Scala 命令的文本文件。
Actually, I noticed that just putting the classpath in quotes prevents this message. The message means it is trying to load a .jar file as a scala program to be interpreted. It can't since it's binary.
实际上,我注意到只需将类路径放在引号中即可防止出现此消息。该消息意味着它正在尝试将 .jar 文件加载为要解释的 Scala 程序。不能,因为它是二进制的。
scala-2.8 "/path/to/jars/*"works fine. The classpath and asterisk is then expanded by Java, not the shell.
scala-2.8 "/path/to/jars/*"工作正常。然后类路径和星号由 Java 扩展,而不是由 shell 扩展。

