Skip to content

Commit

Permalink
feat: add test case of Serializable
Browse files Browse the repository at this point in the history
  • Loading branch information
Planeswalker23 committed May 19, 2021
1 parent d87fcbc commit 941df52
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
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);
}
}

Binary file added test.txt
Binary file not shown.

0 comments on commit 941df52

Please sign in to comment.