File tree Expand file tree Collapse file tree 3 files changed +49
-0
lines changed Expand file tree Collapse file tree 3 files changed +49
-0
lines changed Original file line number Diff line number Diff line change
1
+ package Serialization ;
2
+
3
+ import java .io .*;
4
+
5
+
6
+ class Read_object {
7
+ public static void main (String args []){
8
+ try {
9
+
10
+ FileInputStream fin =new FileInputStream ("class1.txt" );
11
+ ObjectInputStream ois =new ObjectInputStream (fin );
12
+ Student s =(Student )ois .readObject ();
13
+ System .out .println (s .id +" " +s .name );
14
+ ois .close ();
15
+
16
+ System .out .println ("success" );
17
+ }catch (Exception e ){
18
+ System .out .println (e );
19
+ } } }
Original file line number Diff line number Diff line change
1
+ package Serialization ;
2
+ import Serialization .Student ;
3
+ import java .io .Serializable ;
4
+
5
+ class Student implements Serializable {
6
+ int id ;
7
+ String name ;
8
+
9
+ public Student (int id , String name ) {
10
+ this .id = id ;
11
+ this .name = name ;
12
+
13
+ }}
Original file line number Diff line number Diff line change
1
+ package Serialization ;
2
+ import java .io .*;
3
+ import Serialization .Student ;
4
+ public class Write_object {
5
+ public static void main (String args []){
6
+ try {
7
+
8
+ Student s1 =new Student (1549 ,"Ukshit" );
9
+ FileOutputStream fout =new FileOutputStream ("class1.txt" );
10
+ ObjectOutputStream out =new ObjectOutputStream (fout );
11
+ out .writeObject (s1 );
12
+ out .close ();
13
+ System .out .println ("success" );
14
+ }catch (Exception e ){
15
+
16
+ System .out .println (e );
17
+ } } }
You can’t perform that action at this time.
0 commit comments