scala “error: io error while decoding” “with utf-8”

前端 未结 4 1020
悲&欢浪女
悲&欢浪女 2021-02-12 13:31

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?

相关标签:
4条回答
  • 2021-02-12 13:44

    I encountered this problem running sbt "test" with Main.scala, for the indicated reason that it wasn't saved in UTF-8. I fixed it by changing Eclipse Main.scala "File / Properties / Text file encoding / Other" to "UTF-8" and saving.

    0 讨论(0)
  • 2021-02-12 13:50

    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 Object is the name of an main-containing object that you wish to run.

    0 讨论(0)
  • 2021-02-12 13:57

    This will be rare, however in my case this happened because I had a few files that had file ownership set to the company I am consulting at. This not the normal file ownership under security but the microsoft azure protection encryption that you can disable using right click -> File ownership -> Personal (if there is a business domain set there, it is encrypted and needs to be decoded). Windows apps can open the file normally but using non-ms tools, like winrar and seemingly this case, it could not decode the file. Ideally there should be a way to work with the encrypted files but I'm not going to spend time on that here! :)

    0 讨论(0)
  • 2021-02-12 14:05

    I was having this error trying to set a classpath to launch the scala interpreter like scala-2.8 /path/to/jars/*.

    The solutions in this thread Setting multiple jars in java classpath solved my problem; apparently the interpreter was attempting to open a jar file as if it was a text file containing scala commands.

    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.

    scala-2.8 "/path/to/jars/*" works fine. The classpath and asterisk is then expanded by Java, not the shell.

    0 讨论(0)
提交回复
热议问题