1 Star 0 Fork 0

青菜的宝贝/升级窗口

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
SerializableDemo.java 1.08 KB
一键复制 编辑 原始数据 按行查看 历史
青菜的宝贝 提交于 2021-10-24 10:19 . 序列化
class Employee implements Serializable{
private String name;
private int age;
private float salary;
Employee(String name,int age){
this.name=name;
this.age=age;
}
public String toString(){
return "name:"+name+"\n"
+"age:"+age+"\n"
+"salary:"+salary;
}
public void SetAge(int age){
this.age=age;
}
}
public class SerializableDemo {
public static void main(String[] args) throws IOException, ClassNotFoundException {
System.out.println("原来的对象:");
Employee em=new Employee("Qing",19);
System.out.println(em);
ByteArrayOutputStream buff=new ByteArrayOutputStream();
ObjectOutputStream out=new ObjectOutputStream(buff);
out.writeObject(em);
Employee.salary=20000.00;
em.SetAge(24);
ObjectInputStream in=new ObjectInputSream(new ByteArrayInputStream(buff.toByteArray()));
Employee newEm=(Empolyee)in.readObject();
System.out.println("序列化后取出的对象:");
System.out.println(newEm);
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/baby-of-green-vegetables/upgrade-window.git
git@gitee.com:baby-of-green-vegetables/upgrade-window.git
baby-of-green-vegetables
upgrade-window
升级窗口
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385