java nio charset malformedinputexception input length 1

Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2019, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.

Hi, i’m Andrew , an Software Engineer in Test who loves to learn something new in coding and making machines do the routine work instead of me. I’m located in Amsterdam at the moment.

Recently i was adding more values to the resource file in my Fabricator project and , looke like added values that are invalid for UTF-8 encoding. My next trial to execute tests for the project brought me to «MalformedInputException: Input length = 1 » exception. For scala code i managed to find a very easy solution.
Instead of

I’m using now this line of code :

For Java, you’ll have to write a bit more lines of code, but eventually you’ll be able to find your «failing» symbols and maybe change them to UTF-8-proper-ones.

If your file has for example hellö wörld in it, then with .REPLACE command you see the standard unicode replacement character being used:

With .IGNORE , you see the invalid bytes ignored:

Without specifying .onMalformedInput , you get:

Почему выдаёт ошибку?

Содержимое файла: AdresProgramm =D:ЭСЧФ;

1 ответ 1

MalformedInputException возникает если содержимое файла не соответствует заданной кодировке.

Checked exception thrown when an input byte sequence is not legal for given charset, or an input character sequence is not a legal sixteen-bit Unicode sequence.

Источник: computermaker.info

Техника и Гаджеты
Добавить комментарий