给一文本, 找出所有包含“某单词”的句子并输出

package pack1;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class checkword {

void searchword(String word)
{
  File file=new File("aaa.txt");
  try {
    FileReader in=new FileReader(file);
    BufferedReader ins=new BufferedReader(in);//才能读整行
    String str=null;

    while((str=ins.readLine())!=null)//(str=ins.readLine()).length()>0也是同样的作用
    {
      int x=str.indexOf(word);
      if(x!=-1)
      {

        System.out.println("***this sentense has the word:");
        System.out.println(str);
      }
    }
      in.close();
    ins.close();
       } catch (IOException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
}

}
 public static void main(String[] args) {
   // TODO Auto-generated method stub
 checkword one=new checkword();
 one.searchword("baby");
}

}

原题:、给一文本, 找出所有包含“your”的句子  并计算包含个数 按个数排序 并输出

部分要求欠考虑,未实现,望指导

posted on 2015-10-01 15:41  邗影  阅读(856)  评论(3编辑  收藏  举报

导航