All inclusive Charset to avoid “java.nio.charset.MalformedInputException: Input length = 1”?

前端 未结 10 1373
醉话见心
醉话见心 2020-11-30 00:48

I\'m creating a simple wordcount program in Java that reads through a directory\'s text-based files.

However, I keep on getting the error:

java.nio.c         


        
10条回答
  •  孤城傲影
    2020-11-30 01:36

    try this.. i had the same issue, below implementation worked for me

    Reader reader = Files.newBufferedReader(Paths.get(), StandardCharsets.ISO_8859_1);
    

    then use Reader where ever you want.

    foreg:

    CsvToBean csvToBean = null;
        try {
            Reader reader = Files.newBufferedReader(Paths.get(csvFilePath), 
                            StandardCharsets.ISO_8859_1);
            csvToBean = new CsvToBeanBuilder(reader)
                    .withType(anyPojo.class)
                    .withIgnoreLeadingWhiteSpace(true)
                    .withSkipLines(1)
                    .build();
    
        } catch (IOException e) {
            e.printStackTrace();
        }
    

提交回复
热议问题