Scala file read error "Java.nio.charset.MalformedInputException:Input length = 1"

Source: Internet
Author: User

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"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.