import java.util.*; import java.io.*; public class threadRead extends Thread { private String file = null; private String countryName = null; private Thread thread = null; public threadRead(){} //default constructor public threadRead(String fileName){ file = fileName; } public threadRead(String fileName, String country){ file = fileName; countryName = country; } public synchronized void getData(String filename){ file = filename; String line; BufferedReader buf = null; int lineNum = 0; try{ File fr = new File(file);//Create a file handler. if(fr.exists()) //check for file existence. If not then TERMINATE the program right away. buf = new BufferedReader(new FileReader(fr)); else{ System.out.println("File not found!"); System.exit(1); //Terminate the program. } line = buf.readLine();//DO NOT display the first line in the file (it contains StringTokenizer stToken; //field names. Thus we read it OUTSIDE of the WHILE() loop) int seperator = 1; while((line = buf.readLine()) != null){ stToken = new StringTokenizer(line, "\t"); while(stToken.hasMoreTokens()){ String st = stToken.nextToken().trim(); System.out.println("Name : " + st); System.out.println("\t" + stToken.nextToken()); thread.sleep(100); }//end of WHILE(Tokenizer) } //END of inner WHILE. }catch(Exception er){} }//end of getData() public synchronized void getData(String filename, String country){//Method overwriting. String line; BufferedReader buf = null; int lineNum = 0; try{ File fr = new File(filename);//Create a file handler. if(fr.exists()) //Check for file existence. If not then TERMINATE the program right away. buf = new BufferedReader(new FileReader(fr)); else{ System.out.println("File not found!"); System.exit(1); //Terminate the program. } buf = new BufferedReader(new FileReader(filename)); line = buf.readLine();//DO NOT display the first line in the file (it contains StringTokenizer stToken; //field names. Thus we read it OUTSIDE of the WHILE() loop) int seperator = 1; while((line = buf.readLine()) != null){ String tmp = ""; stToken = new StringTokenizer(line, "\t"); while(stToken.hasMoreTokens()){ if(stToken.nextToken().compareToIgnoreCase(country.trim()) == 0){ System.out.println(line);//print the entire record (which is "line") }//end of IF() }//end of WHILE(Tokenizer) } //END of inner WHILE. }catch(Exception er){} }//end of getData(String, String) public void run(){ getData(file); }//end of run() }//end of class threadRead{}