Why is my BufferedReader reading text that dosn't exit in the given file?

南楼画角 提交于 2019-12-02 04:36:27

What you see is the UTF-8 BOM

Convert your input file to be without BOM.

Follow this code:

        String lineFromFile = bufferedReader.readLine();
        // strip out the `[` and `]`
        lineFromFile = lineFromFile.substring(1, lineFromFile.length()-1);
        StringBuilder sb = new StringBuilder();
        for(String s: lineFromFile.split(", "))
            sb.append((char) Integer.parseInt(s));
        String text = sb.toString();

white spaces may cos this error. try to trim() the input line while reading line,

like,

line = bufferedReader.readLine().trim();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!