读取的文件是这样的  
#Version: 1.0#Start-Date: 2008-08-19 20:30:53#Software: Adobe Flash Media Server 3.0.2 r210#Date: 2008-08-19#Fields: date time x-pid x-status x-ctx x-comment2008-08-19 20:30:53 456 (i)2651170 Unloaded application instance admin -
2008-08-19 20:30:53 456 (i)2651170 Unloaded application instance admin -
2008-08-19 20:30:53 456 (i)2651170 Unloaded application instance admin -如何通过一行一行的读取,但是只要是开头是#开头的就不读这一行  也就是我只要读里面的
2008-08-19 20:30:53 456 (i)2651170 Unloaded application instance admin -
2008-08-19 20:30:53 456 (i)2651170 Unloaded application instance admin -
2008-08-19 20:30:53 456 (i)2651170 Unloaded application instance admin -
这3行  请教一下~~~~~~~

解决方案 »

  1.   

     try {
                BufferedReader in = new BufferedReader(new FileReader("d:\\xx.txt"));
                String s = "";
                while ((s = in.readLine()) != null) {
                    if (s.startsWith("#")) {
                        s = in.readLine();
                        continue;
                    }
                    System.out.println(s);
                }
                
                in.close();
                
            } catch (FileNotFoundException e) {
                // TODO 自动生成 catch 块
                e.printStackTrace();
            } catch (IOException e) {
                // TODO 自动生成 catch 块
                e.printStackTrace();
            }
      

  2.   

    楼上回答很好,不过要是把:
    if (s.startsWith("#")) {
                        s = in.readLine();
                        continue;
                    }
    System.out.println(s);
    改成
    if (!s.startsWith("#")) {
                        s = in.readLine();
                        System.out.println(s);
                    }
    会更好点,因为java不推荐用continue
      

  3.   

    if (s.startsWith("#")) {
       s = in.readLine();
       continue;
    }这里应该是直接写成
    if (s.startsWith("#") || s.trim().length == 0) 
      continue;

    s = in.readLine; 是可以去掉的
      

  4.   

    while ((s = in.readLine()) != null) {
                    if (!s.startsWith("#")) {
                        System.out.println(s);
                    }
                    
    }