You are reading lines from the file and assigning its content to str
, but you never do something with this value.
Also, Student
seems to be empty.
Supposing your file includes only the ID of the student:
BufferedReader read = new BufferedReader(new FileReader(file));
String str;
while((str=read.readLine())!=null)
{
// Your constructor assigns str to ID property of Student
// Casting to Integer, because ID is a number
Student s = new Student(Integer.valueOf(str));
if(s.getId()==id)
System.out.println(s.print());
}
Also, make sure your print()
method in Student really prints what you want.
solved Search Student in File