Skip to content

Commit 0f674e9

Browse files
Add files via upload
1 parent b268d36 commit 0f674e9

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

JavaGenMUB8.java

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import java.io.File;
2+
import java.io.FileInputStream;
3+
import java.io.FileOutputStream;
4+
import java.io.IOException;
5+
import java.io.ObjectInputStream;
6+
import java.io.ObjectOutputStream;
7+
import java.io.Serializable;
8+
9+
public class JavaGenMUB8<T extends Number & Serializable> {
10+
T path;
11+
T name;
12+
13+
public JavaGenMUB8(T path) {
14+
this.path = path;
15+
}
16+
17+
public T serialize(T name) {
18+
this.name = name;
19+
try {
20+
File f = new File(path.toString());
21+
FileOutputStream file = new FileOutputStream(f);
22+
ObjectOutputStream out = new ObjectOutputStream(file);
23+
out.writeObject(name);
24+
System.out.println("Object has been successfully serialized... ");
25+
out.close();
26+
file.close();
27+
} catch (IOException e) {
28+
e.printStackTrace();
29+
}
30+
return null;
31+
32+
}
33+
34+
public T deserialize() {
35+
try {
36+
File f = new File(path.toString());
37+
FileInputStream file = new FileInputStream(f);
38+
ObjectInputStream in = new ObjectInputStream(file);
39+
T name1 = (T) in.readObject();
40+
System.out.println("name1 = " + name1);
41+
System.out.println("Object has been successfully deserialized... ");
42+
in.close();
43+
file.close();
44+
} catch (IOException e) {
45+
e.printStackTrace();
46+
} catch (ClassNotFoundException e) {
47+
e.printStackTrace();
48+
}
49+
return null;
50+
}
51+
52+
public static void main(String[] args) {
53+
54+
JavaGenMUB8<Integer> obj = new JavaGenMUB8<>(10);
55+
obj.serialize(100);
56+
obj.deserialize();
57+
58+
}
59+
60+
}

0 commit comments

Comments
 (0)