Java read file got a leading BOM [  ]

前端 未结 6 1288
孤独总比滥情好
孤独总比滥情好 2020-12-20 23:15

I am reading a file containing keywords line by line and found a strange problem. I hope lines that following each other if their contents are the same, they should be handl

6条回答
  •  自闭症患者
    2020-12-21 00:06

    Try trimming whitespace at the beginning and end of lines read. Just replace your while with:

    while ((strLine = bufferedReader.readLine()) != null) {
            strLine = strLine.trim();
            logger.info(Arrays.toString(strLine.toCharArray()));
        if(strLine.contentEquals(prevLine)){
            logger.info("Skipping the duplicate lines " + strLine);
            continue;
        }
        prevLine = strLine;
    }
    

提交回复
热议问题