我把文本中的学生信息写入了一个集合,但是查找时,却无法查找成功
private static String[] student;
public static void R(String n) throws IOException{
Student stu = new Student();
File file = new File("D:\\","aa.txt");
FileInputStream intput = new FileInputStream(file);
BufferedReader br = new BufferedReader(new InputStreamReader(intput));
String t;
List<String>list = new ArrayList<>();
while ((t=br.readLine())!=null){
list.add(t);
}
for (String students:list) student = students.split(",");
for (String students:list){
if (students.equals(n)){
System.out.println(stu+"查找成功!");
}
else{
System.out.println("该学生不存在");
break;
}
}
}
public static void main(String[] args) {
System.out.println("输入你要查找的学生姓名:");
Scanner scanner = new Scanner(System.in);
String n = scanner.nextLine();
try {
R(n);
} catch (IOException e) {
e.printStackTrace();
}
}