public class lianxi
{
public static void main(String[] args) throws IOException
{
File f= new File("C:\\Documents and Settings\\ttc\\桌面\\录像\\src\\dept.java");
FileReader fr=new FileReader(f);
BufferedReader br=new BufferedReader(fr);
List<String> list=new ArrayList<String>();
String str=null;
int s=1;
while((str=br.readLine())!=null)
{
list.add(str);
}
System.out.println("请输入要查找的单词");
Scanner sc = new Scanner(System.in);
String strword = sc.nextLine();
for(String stra:list)
{
boolean b = fangfa1(stra,strword);
if(b){
System.out.println(s+":"+stra);
}
s++;
}
}
public static boolean fangfa1(String s1,String s2)
{
if (s1.indexOf(s2)>=0)
{
return true;
}else {
return false;
}
}
}
查找文件中单词所在的段落
最新推荐文章于 2024-08-05 16:41:06 发布