Skip to content

Commit 3acd16c

Browse files
Add files via upload
1 parent 21c571b commit 3acd16c

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

Serialization/Read_object.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
} } }

Serialization/Serialization_1.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
}}

Serialization/Write_object.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
} } }

0 commit comments

Comments
 (0)