BufferReader readLine的一个bug

问题描述:readLine第一行的首字符是个空字符
解决:

    @Test
    public void getTemperature() throws IOException {
        BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(new FileInputStream(
                new File("C:\\Users\\Administrator\\Desktop\\2015-weather-data.txt"))));

        String line="";
        int lineNumber=0;
        while ((line=bufferedReader.readLine())!=null){
//            readLine()有个bug,第一行的首字符是个空字符""
            if (lineNumber==0){
                line=line.substring(1);
            }
            String time=line.trim().substring(15, 27);
            String temperature;
            if(line.charAt(87)=='+'){
             temperature=line.trim().substring(88, 92);
            }else{
                temperature=line.trim().substring(87, 92);
            }
            System.out.println("时间:"+time +" 温度:"+temperature);
            lineNumber++;
        }
        bufferedReader.close();
    }

你可能感兴趣的:(BufferReader readLine的一个bug)