【发布时间】:2016-05-10 11:16:54
【问题描述】:
我正在尝试使用流来读取文件,但我无法通过异常。我一直在环顾四周,但我就是不明白它为什么会被抛出。
我要读取的文件是file.txt,它是用UTF-8编码的。
我正在使用Files.lines()阅读它:
String path = FileWordCount.class.getResource("file.txt").getPath().substring(1);
Files.lines(Paths.get(path), Charset.forName("UTF-8")).forEach(System.out::println);
尝试读取文件时出现以下异常:
Exception in thread "main" java.io.UncheckedIOException: java.nio.charset.MalformedInputException: Input length = 1
[...]
Caused by: java.nio.charset.MalformedInputException: Input length = 1
通常我不会发布有关异常的简单问题,但我只是想出这个问题。
【问题讨论】:
-
这可能是相关的:stackoverflow.com/questions/26268132/… ?