Kubernetes 入门到进阶实战
download:Kubernetes 入门到进阶实战
import java.io.*;
public class SerializeDemo
{
public static void main(String [] args)
{
Employee e = new Employee();
e.name = "Reyan Ali";
e.address = "Phokka Kuan, Ambehta Peer";
e.SSN = 11122333;
e.number = 101;
try
{
FileOutputStream fileOut =
new FileOutputStream("/tmp/employee.ser");
ObjectOutputStream out = new ObjectOutputStream(fileOut);
out.writeObject(e);
out.close();
fileOut.close();
System.out.printf("Serialized data is saved in /tmp/employee.ser");
}catch(IOException i)
{
i.printStackTrace();
}
}
}
反序列化对象
下面的 DeserializeDemo 程序实例了反序列化,/tmp/employee.ser 存储了 Employee 对象。
DeserializeDemo.java 文件代码:
import java.io.*;
public class DeserializeDemo
{
public static void main(String [] args)
{
Employee e = null;
try
{
FileInputStream fileIn = new FileInputStream("/tmp/employee.ser");
ObjectInputStream in = new ObjectInputStream(fileIn);
e = (Employee) in.readObject();
in.close();
fileIn.close();
}catch(IOException i)
{
i.printStackTrace();
return;
}catch(ClassNotFoundException c)
{
System.out.println("Employee class not found");
c.printStackTrace();
return;
}
System.out.println("Deserialized Employee...");
System.out.println("Name: " + e.name);
System.out.println("Address: " + e.address);
System.out.println("SSN: " + e.SSN);
System.out.println("Number: " + e.number);
}
}
更多相关文章
- Java 对象的哈希值是每次 hashCode() 方法调用重计算么?
- JS对象与流程控制
- 使用原生 js 和 Vue 路由模块分别实现一个前端路由
- 值得收藏的免费P图工具:用Ai一键替换照片中的任意元素
- Java程序员必备基础:Object的十二个知识点
- 原生js实现简单的链式操作
- JAVA垃圾回收机制
- js 中数组常用方法介绍以及 JSON 对象的两个方法展示和跨域请求
- Apache Flink 进阶(六):Flink 作业执行深度解析