java - Search Student in File -


i search in input file students. here overview of work far.

class student, setters, getters , display method (print)

class studentfile

import java.io.*; import java.util.arraylist; public class studentfile {  public void trouver(int id)      {         try         {         file file = new file("c:/users/akram/documents/akram.txt");         bufferedreader read = new bufferedreader(new filereader(file));         string str;          while((str=read.readline())!=null)          {             student s;              if(s.getid()==id)                 system.out.println(s.print());          }          read.close();             }         catch(ioexception e) { system.out.println(e); }     } } 

this method display nothing, , i'm not sure why. have insight?

you reading lines file , assigning content str, never value.

also, student seems empty.

supposing file includes id of student:

bufferedreader read = new bufferedreader(new filereader(file));     string str;      while((str=read.readline())!=null)      {         // constructor assigns str id property of student         // casting integer, because id number         student s = new student(integer.valueof(str));           if(s.getid()==id)             system.out.println(s.print());      } 

also, make sure print() method in student prints want.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -