Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



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

Have Programming Question? Ask it here!
 
 
 


java
i want a java program using randamacessfile with emp details.(taking values from enduser read,save,write,readfile give output on console
0 Answer(s)      a year and 3 months ago
Posted in : Java Beginners


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);


Advertisement
View Answers

Related Tutorials/Questions & Answers:
 

 

 

DMCA.com