All inclusive Charset to avoid “java.nio.charset.MalformedInputException: Input length = 1”?

前端 未结 10 1378
醉话见心
醉话见心 2020-11-30 00:48

I\'m creating a simple wordcount program in Java that reads through a directory\'s text-based files.

However, I keep on getting the error:

java.nio.c         


        
10条回答
  •  盖世英雄少女心
    2020-11-30 01:22

    ISO-8859-1 is an all-inclusive charset, in the sense that it's guaranteed not to throw MalformedInputException. So it's good for debugging, even if your input is not in this charset. So:-

    req.setCharacterEncoding("ISO-8859-1");
    

    I had some double-right-quote/double-left-quote characters in my input, and both US-ASCII and UTF-8 threw MalformedInputException on them, but ISO-8859-1 worked.

提交回复
热议问题