The problem with writing the Spark program today is that there was a mistake in reading the file: "Exception in Thread" main "java.nio.charset.MalformedInputException:Input Length = 1 "
The code to read the file is as follows:
A look at this wrong "NiO" error, the first feeling is to read the file method here out of the question, so click to see the Source.fromfile this method of source code:
Sure enough, there are several overloads of this method, but each one directly or indirectly needs to specify the encoding of the read file, that is, what code you need to read the file you need to read, because my idea sets the encoding when UTF-8
Therefore, if you use UTF-8 to read the GBK file, you will need to specify a read encoding of GBK.
Or
Both of these ways can be, all from the source.
After the setup is complete, rerun the program and the error disappears.
Scala file read error "Java.nio.charset.MalformedInputException:Input length = 1"