package iopack;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import pkg.Student;
public class SerializationTest {
public static void main(String[] args)
{
Student s = new Student("Ram",5005,"MCA",5);
ObjectOutputStream oos = null;
try
{
oos = new ObjectOutputStream(new FileOutputStream("D:\\Stud.ser"));
oos.writeObject(s);
System.out.println("Write done");
}
catch (FileNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
try
{
oos.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
ObjectInputStream ois =null;
try
{
ois = new ObjectInputStream(new FileInputStream("D:\\Stud.ser"));
Student ss =(Student) ois.readObject();
System.out.println(ss);
}
catch (FileNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (ClassNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
try
{
ois.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
}
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import pkg.Student;
public class SerializationTest {
public static void main(String[] args)
{
Student s = new Student("Ram",5005,"MCA",5);
ObjectOutputStream oos = null;
try
{
oos = new ObjectOutputStream(new FileOutputStream("D:\\Stud.ser"));
oos.writeObject(s);
System.out.println("Write done");
}
catch (FileNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
try
{
oos.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
ObjectInputStream ois =null;
try
{
ois = new ObjectInputStream(new FileInputStream("D:\\Stud.ser"));
Student ss =(Student) ois.readObject();
System.out.println(ss);
}
catch (FileNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (ClassNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
try
{
ois.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
}