完整的错误消息:
java.nio.charset.UnmappableCharacterException: Input length = 1
at java.nio.charset.CoderResult.throwException(CoderResult.java:261)
at sun.nio.cs.StreamEncoder.implWrite(StreamEncoder.java:266)
at sun.nio.cs.StreamEncoder.write(StreamEncoder.java:106)
at sun.nio.cs.StreamEncoder.write(StreamEncoder.java:116)
at java.io.Writer.write(Writer.java:140)
at scala.xml.XML$.write(XML.scala:108)
at scala.xml.XML$$anonfun$save$2.apply$mcV$sp(XML.scala:91)
at scala.xml.XML$$anonfun$save$2.apply(XML.scala:91)
at scala.xml.XML$$anonfun$save$2.apply(XML.scala:91)
at scala.util.control.Exception$Catch.apply(Exception.scala:102)
at scala.xml.XML$.save(XML.scala:90)
at agent.Main$$anonfun$2.apply$mcV$sp(Main.scala:32)
我在第32行的代码:
scala.xml.XML.save(nameBuilder(),file)
我需要在这里更改什么?文件中是否有不可打印的字符?
提前致谢
答案 0 :(得分:6)
您必须提供正确的编码。 save方法将其作为参数。 见http://www.scala-lang.org/api/2.10.4/index.html#scala.xml.XML%24
scala.xml.XML.save(nameBuilder(),file, "UTF-8")