别晕啊,给我一点希望好不好
用stream怎么做?是循环读吗
我是一次把它读出来BufferedReader  br=new  BufferedReader(new  FileReader("C:\\sp3.log"));  怎样循环读

解决方案 »

  1.   

    import  java.io.*;  
    public  class  textsearch  {              
       public  static  void  main(String[]  args)    
        {  
         try  
        {  
           int  megamount=0;  
           BufferedReader  br=new  BufferedReader(new  FileReader("C:\\sp3.log"));  
          
           String  linestr= null;
           String  pstr = "Send  To  Mobile  Message";
           int  i=0,j=0,m=0; 
           int pos=0;
            
           while(true)  
          {  
              // String  linestr=br.readLine();  
              //最好不要在循环内声明变量 
               inestr=br.readLine();  
               if(linestr==null)  break;  
               else  
              {  
                          System.out.println(linestr);         
               //int  i=0,j=0,m=0;  
              // String  pstr="Send  To  Mobile  Message";  
               
               pos = 0; 
               do                     
               { pos=linestr.indexof(pstr, pos);
                  if(pos>-1){
                     megamount+=1;
               }while (pos=-1)          
                 
              /* for(i=0;i<linestr.length();i++)  
               {  
                     if(linestr.charAt(i)==pstr.charAt(0))  
                    {  
                          m=i;  
                         //if(linestr.charAt(m)==pstr.charAt(j))System.out.println("----
                          "+linestr.charAt(m)+"---------"+pstr.charAt(j));  
                         for(j=0;j<pstr.length()&&m<linestr.length()&&linestr.charAt(m)
                                ==pstr.charAt(j);m++,j++);  
                         if(j==pstr.length())  
                         {  
                               megamount+=1;  
                         }  
                    }  
               }*/  
            }  
     }  
      System.out.println("The  amout  is  -----------------"+megamount+"----------------------");  
     }catch(Exception  e){}  
    }  
    }
      

  2.   

    另外,用regionMatches()涵数也可以查找匹配子串
    好象用法如下:你可以试试
    String s1="abcdefghiadss";
    String s2="abc";
    s1.regionMatches(true,1,s2,1,s1.length()) ;
            
    参数1:指示是否忽略大小写
    参数2:开始查找此字符串的位置
    参数3:另一个字符串
    参数4:另一个字符串内开始查找的地址
    参数5:字符串长度
      

  3.   

    有几个地方错了!改正如下:import  java.io.*;  
    public  class  textsearch  {              
       public  static  void  main(String[]  args)    
        {  
         try  
        {  
           int  megamount=0;  
           BufferedReader  br=new  BufferedReader(new  FileReader("C:\\sp3.log")); 
          
           String  linestr= null;
           String  pstr = "o";
           int  i=0,j=0,m=0; 
           int pos=0;
         
             
           while(true)  
          {  
              // String  linestr=br.readLine();  
              //最好不要在循环内声明变量  
              
               linestr=br.readLine(); 
               System.out.println(linestr);
               if(linestr==null)  break;  
               else  
              {  
               //int  i=0,j=0,m=0;  
              // String  pstr="Send  To  Mobile  Message";  
               
               pos = -1; 
               do                     
               { pos=linestr.indexOf(pstr,pos+1);
                  if(pos>-1){
                     megamount+=1;
                    }                          
               }while (pos>-1) ;         
                 
              /* for(i=0;i<linestr.length();i++)  
               {  
                     if(linestr.charAt(i)==pstr.charAt(0))  
                    {  
                          m=i;  
                         //if(linestr.charAt(m)==pstr.charAt(j))System.out.println("----
                          "+linestr.charAt(m)+"---------"+pstr.charAt(j));  
                         for(j=0;j<pstr.length()&&m<linestr.length()&&linestr.charAt(m)
                                ==pstr.charAt(j);m++,j++);  
                         if(j==pstr.length())  
                         {  
                               megamount+=1;  
                         }  
                    }  
               }*/  
            }  
     }  
      System.out.println("The  amout  is  -----------------"+megamount+"----------------------");  
     }catch(Exception  e){}  
    }  
    }另:
    BufferedReader br=new BufferedReader(new FileReader(filename))不限制文件大小
      

  4.   

    good!
    谢谢hpy121!
    很感谢!