import java.io.*;
public class First {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
//Employee e;
Employee j[] = new Employee[10];
int k;
//BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
FileOutputStream fout = new FileOutputStream("file.txt");
ObjectOutputStream obj = new ObjectOutputStream(fout);
FileInputStream fin = new FileInputStream("file.txt");
ObjectInputStream obj1 = new ObjectInputStream(fin);
//k = Integer.parseInt(br.readLine());
//System.out.println("How many objects do you need to creat?");
for(int i=0;i<10;i++){
j[i]=new Employee(10,"Sai");
obj.writeObject(j[i]);
}
obj.close();
Employee e;
try {
while((e = (Employee)obj1.readObject())!= null){
e.display();
}
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
System.out.println("The value of Obj is");
e1.printStackTrace();
}
catch (EOFException e1) {
// TODO Auto-generated catch block
System.out.println("Reached EOF");
e1.printStackTrace();
}
}
}
import java.io.*;
public class Employee implements Serializable {
private int age;
private String name;
Employee(int i,String s){
this.age=i;
this.name=s;
}
void display(){
System.out.println("The values of the object are " +name +"\t" +age );
}
}
public class First {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
//Employee e;
Employee j[] = new Employee[10];
int k;
//BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
FileOutputStream fout = new FileOutputStream("file.txt");
ObjectOutputStream obj = new ObjectOutputStream(fout);
FileInputStream fin = new FileInputStream("file.txt");
ObjectInputStream obj1 = new ObjectInputStream(fin);
//k = Integer.parseInt(br.readLine());
//System.out.println("How many objects do you need to creat?");
for(int i=0;i<10;i++){
j[i]=new Employee(10,"Sai");
obj.writeObject(j[i]);
}
obj.close();
Employee e;
try {
while((e = (Employee)obj1.readObject())!= null){
e.display();
}
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
System.out.println("The value of Obj is");
e1.printStackTrace();
}
catch (EOFException e1) {
// TODO Auto-generated catch block
System.out.println("Reached EOF");
e1.printStackTrace();
}
}
}
import java.io.*;
public class Employee implements Serializable {
private int age;
private String name;
Employee(int i,String s){
this.age=i;
this.name=s;
}
void display(){
System.out.println("The values of the object are " +name +"\t" +age );
}
}
output:-
No comments:
Post a Comment