我的写的代码,为什么总是行读取,不能全部读取呢?请高手帮忙
代码如下:
我的代码如下BufferedReader br = null;
  PrintWriter pw = null;
  String str = null;
  try {
   br = new BufferedReader(new InputStreamReader(new FileInputStream("E:iptv_CCTV_AUTO_scheduler.log")));
   pw = new PrintWriter(new FileWriter("E:/25_new.txt"),true);
   while(br.readLine() != null){
    str = br.readLine();
    if(str.indexOf("INFO") != -1){
     pw.println(str);
    }
    if(str.indexOf("ConnectCount") != -1){
     pw.println(str);
    }
   }
  } catch (FileNotFoundException e) {
   e.printStackTrace();
  } catch (IOException e) {
   e.printStackTrace();
  } finally{
   try {
    pw.flush();
    br.close();
   } catch (IOException e) {
    e.printStackTrace();
   }
  }

解决方案 »

  1.   

      while(br.readLine() != null){
        str = br.readLine();
    =>
    连读两次,你把其中一次丢掉了。
      

  2.   


    就是这样,可以改为while((str  = br.readLine() ) != null){
       
      

  3.   


    您应该没明白我的意思,我是要把所有含有"INFO"和"ConnectCount"的行提取出来,但总是会少一半。
    后面我试了试全部读取发现默认隔行读取数据,是我的代码有问题还是log文件的问题??
      

  4.   

    for(String str = br.readLine(); str != null; str = br.readLine()){