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

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   邗影  阅读(868)  评论(3编辑  收藏  举报

努力加载评论中...
< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8

导航

统计

点击右上角即可分享
微信分享提示