java读取文件 javaniocharsetMalformedInputException Input length = 1
这个错误通常是因为文件的编码格式与你的程序使用的编码格式不一致导致的。
解决方法:
-
确认文件的编码格式,可以使用文本编辑器打开文件并查看编码格式,一般为UTF-8或者GBK。
-
在读取文件时指定正确的编码格式,例如:
File file = new File("file.txt");
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
其中,"UTF-8"应该替换为文件实际的编码格式。
原文地址: https://www.cveoy.top/t/topic/gJMI 著作权归作者所有。请勿转载和采集!