我的代码抛出异常
Exception in thread "main" java.io.UncheckedIOException: java.nio.charset.MalformedInputException: Input length = 1
at java.io.BufferedReader$1.hasNext(BufferedReader.java:574)
at java.util.Iterator.forEachRemaining(Iterator.java:115)
at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
at java.util.stream.ReferencePipeline$Head.forEachOrdered(ReferencePipeline.java:590)
执行此行时
Files.lines(in.toPath()).forEachOrdered(new Consumer<String>() {
@Override
public void accept(String s) {
//stuff
});
当然,由于编码,文本会出现乱码,如果我选择&#34;转换为UTF-8&#34;来自&#34;编码&#34;菜单然后它显示正确
这让我认为UTF-8是正确的编码,但是根据Java文档,Files.lines()默认使用UTF-8编码(它相当于Files.lines(path,StandardCharsets.UTF_8) ))但是当阅读带有日文文本的文件时它仍然会中断,我该如何处理?