• Post Reply Bookmark Topic Watch Topic
  • New Topic

how can i read this

 
ameem sami
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The thing which i want to know is that i want to read data from a file ,data is in the following format
empno name sal
111 Sam 5000
222 John 6000
333 Susan 4900

how can i read this data from a file ,when the user enters his or her empno rest of the information is also fetched ,how can i do this.There should be a searching routine to search file.
Can any one help me on this stuff,i would be thankful
 
lee dalais
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Ameem
u should look at the BufferedReader class, u can use the readLine method, then u should be able to manipulate the readin line to find out the values
 
Roshini Sridharan
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ameem
As lee mentioned use Buffered Reader readline() and to parse the values use StringTokenzier based on the space as the delimiter. Hope so this will help u.
Roshini
 
ameem sami
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you help with a piece of code
because i didnt got much help ,
thanks in advance
 
atif wasi
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
abey kutay,
u should talk with me on phone, i will tell u all kind of stuff
bye
 
atif wasi
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
dont feel bad, u should call me i will solve ur problem
ur friend
atif
------------------
 
srinivasrao marri
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
check for the below given solution
import java.io.*;
import java.util.*;
class ReadData{
public static void main(String args[])throws Exception{
int x;
File fl=new File("d:\\testjava\\record.txt");
int len=(int)fl.length();
BufferedReader in=new BufferedReader(new FileReader(fl));
System.out.println(in.readLine());
try{

for(int i=0; i<len; i++){>

String line=in.readLine();
StringTokenizer stz=new StringTokenizer(line," ");
int empno=Integer.parseInt(stz.nextToken());
String name=stz.nextToken();
int sal=Integer.parseInt(stz.nextToken());
int n=Integer.parseInt(args[0]);
if(empno==n)
System.out.println(empno+" "+name+" "+sal);
}

}catch(Exception e){}
}
}
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!