Stream <string>处理中的MalformedInputException

时间:2015-06-24 21:36:14

标签: java character-encoding java-8 java-stream

此代码似乎返回java.nio.charset.MalformedInputException: Input length = 1错误,而在我的生活中,我无法弄清楚原因。

Files.lines(Paths.get(fileName))
            .forEachOrdered(m -> hashmap.put(LocalDateTime.MIN, m));

hashmap是HashMap<LocalDateTime, String>

完整堆栈错误:

Exception in thread "main" java.io.UncheckedIOException: java.nio.charset.MalformedInputException: Input length = 1
    at java.io.BufferedReader$1.hasNext(Unknown Source)
    at java.util.Iterator.forEachRemaining(Unknown Source)
    at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Unknown Source)
    at java.util.stream.ReferencePipeline$Head.forEachOrdered(Unknown Source)
    at FileHandler.inputSavedDonations(FileHandler.java:92)
    at StreamHelper.main(StreamHelper.java:36)
Caused by: java.nio.charset.MalformedInputException: Input length = 1
    at java.nio.charset.CoderResult.throwException(Unknown Source)
    at sun.nio.cs.StreamDecoder.implRead(Unknown Source)
    at sun.nio.cs.StreamDecoder.read(Unknown Source)
    at java.io.InputStreamReader.read(Unknown Source)
    at java.io.BufferedReader.fill(Unknown Source)
    at java.io.BufferedReader.readLine(Unknown Source)
    at java.io.BufferedReader.readLine(Unknown Source)
    ... 6 more

第92行是.forEachOrdered(m -> hashmap.put(LocalDateTime.MIN, m));

fileName声明:private static String fileName = "file";

0 个答案:

没有答案