如何在java中的文本文件中搜索某个单词?使用缓冲阅读器,我有这段代码,但我得到了
java.lang.ArrayIndexOutOfBoundsException
请帮我确定我的程序有什么问题。
System.out.println("Input name: ");
String tmp_name=input.nextLine();
try{
FileReader fr;
fr = new FileReader (new File("F:\\names.txt"));
BufferedReader br = new BufferedReader (fr);
String s;
while ((s = br.readLine()) != null) {
String[] st = s.split(" ");
String idfromtextfile=st[0];
String nemfromtextfile = st[1];
String scorefromtextfile=st[2];
if(nemfromtextfile.equals(tmp_name)){
System.out.println("found");
}else{
System.out.println("not found");
}
}
}catch(Exception e){ System.out.println(e);}
names.txt 看起来像这样:
1
a
0
2
b
0