bug记录----Java NIO 报java.nio.charset.MalformedInputException: Input length = 1

Posted 幸运的大米

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了bug记录----Java NIO 报java.nio.charset.MalformedInputException: Input length = 1相关的知识,希望对你有一定的参考价值。

请求异常报错:Java NIO 报java.nio.charset.MalformedInputException: Input length = 1 原因:项目启动时未设置默认编码,代码中又获取了系统默认编码(在windows环境下,ADT 编译器默认编码方式GBK)。 使用的类是:org.apache.commons.io中的IOUtils public static byte[] toByteArray(Reader input) throws IOException { return toByteArray(input, Charset.defaultCharset()); } 解决: 1.在代码中设置默认编码; 2.项目启动时设置环境默认编码; 方法一、修改环境变量 (变量名:JAVA_TOOL_OPTIONS变量值:-Dfile.encoding=UTF-8) 方法二、tomcat中修改:修改catalina.bat(或startup.sh),在文件头中添加:set -Dfile.encoding=utf-8 方法三、idea中添加VM options:-Dfile.encoding=utf-8

以上是关于bug记录----Java NIO 报java.nio.charset.MalformedInputException: Input length = 1的主要内容,如果未能解决你的问题,请参考以下文章

错误记录Flutter 混合开发报错 ( java.nio.file.FileSystemException: xxx/R.jar: 另一个程序正在使用此文件,进程无法访问。 )

Java nio 空轮询bug到底是什么

Java项目BUG记录(找BUG笔记)

JDK NIO SelectionKey bug

记录一些遇见的bug——项目启动报错org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.e

记录一些遇见的bug——项目启动报错org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.e