i want a java program using randamacessfile with emp details.(taking values from enduser read,save,write,readfile give output on console

i want a java program using randamacessfile with emp details.(taking values from enduser read,save,write,readfile give output on console

import java.io.*;
Class RandomAcess1
int idno;
String name;
float sal;
RandomAcessFile raf;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
RandomAcess1()
{
try{raf=new RandomAcessFile("emp.dat","rw");
}catch(Exception e)
{System.out.prinntln((e);}}
public void readEmp()
{
try{
System.out.println("enter the idno of employe");
idno=Integer.parseInt(br.readLine().trim());
System.out.pritnln("enter name");
name=br.readLine();
System.out.println("enter sal");
sal=float.parsefloat (br.readLine().trim());
}catch(Exception e)
{System.out.println(e);}}
public void writeFile()
{
String ch="yes";
try{
raf.seek(raf.length());
while(ch.equals("yes"));
{
readEmp();
raf.writeInt(Idno);
raf.writeUTF(name);
raf.writefloat(sal);
System.out.println("any more rec's?");
ch=br.readLine().trim();
}
readFile();
raf.close();
}catch(xception e)
{System.out.println(e);
}
}
pulic void readFile()
{
try{
raf.seek(0);

View Answers

May 22, 2013 at 11:58 AM

hi friend,

See the tutorial Using a Random Access File in Java

Thanks.









Related Tutorials/Questions & Answers:

Ads