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

后端 未结 3 567
渐次进展
渐次进展 2021-01-25 23:06

I am using a BufferedReader to read details from a file which are stored as bytes, I am then converting the bytes into text and splitting it into an

相关标签:
3条回答
  • 2021-01-25 23:32

    What you see is the UTF-8 BOM

    Convert your input file to be without BOM.

    0 讨论(0)
  • 2021-01-25 23:42

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

    like,

    line = bufferedReader.readLine().trim();
    
    0 讨论(0)
  • 2021-01-25 23:48
    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();
    
    0 讨论(0)
提交回复
热议问题