-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d87fcbc
commit 941df52
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
jdk/src/main/java/io/walkers/planes/pandora/jdk/TestSerializable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package io.walkers.planes.pandora.jdk; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
|
||
import java.io.*; | ||
|
||
/** | ||
* {@link Serializable} 测试类 | ||
* @author planeswalker23 | ||
* @see java.io.Serializable | ||
*/ | ||
@Data | ||
@AllArgsConstructor | ||
public class TestSerializable implements Serializable { | ||
|
||
private String data; | ||
|
||
public static void main(String[] args) throws IOException, ClassNotFoundException { | ||
TestSerializable sourceObject = new TestSerializable("1"); | ||
|
||
FileOutputStream fileOutputStream = new FileOutputStream("test.txt"); | ||
ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream); | ||
objectOutputStream.writeObject(sourceObject); | ||
objectOutputStream.flush(); | ||
objectOutputStream.close(); | ||
|
||
//反序列化 | ||
FileInputStream fileInputStream = new FileInputStream("test.txt"); | ||
ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream); | ||
TestSerializable targetObject = (TestSerializable) objectInputStream.readObject(); | ||
|
||
System.out.println(targetObject); | ||
} | ||
} | ||
|