当前位置:网站首页>对象的序列化与反序列化
对象的序列化与反序列化
2022-07-01 04:46:00 【洋啊桑815】
import java.io.*;
public class Test1 {
public static void main(String[] args) throws Exception {
//对象序列化
//创建对象
Student s=new Student("李华");
ObjectOutputStream ops=
new ObjectOutputStream(new FileOutputStream(""));
//直接调用序列化方法
ops.writeObject(s);
ops.close();
//反序列化
ObjectInputStream oin=new ObjectInputStream(new FileInputStream(""));
Student ss=(Student) oin.readObject();
oin.close();
}
}
class Student implements Serializable{
//声明序列化版本号
//序列化与反序列化的版本号必须一致,有改动就要先序列化才能反序列化
private static final long SerializableNumber=1;
//成员变量使用transient修饰 就不可以被序列化
private String name;
public Student() {
}
public Student(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "Student{" +
"name='" + name + '\'' +
'}';
}
}边栏推荐
- 2022 gas examination question bank and online simulation examination
- Take a cold bath
- PR 2021 quick start tutorial, learn about the and functions of the timeline panel
- Pytest automated testing - compare robotframework framework
- How to use common datasets in pytorch
- Kodori tree board
- 2022 t elevator repair question bank and simulation test
- C - detailed explanation of operators and summary of use cases
- Basic skeleton of neural network nn Use of moudle
- Strategic suggestions and future development trend of global and Chinese vibration isolator market investment report 2022 Edition
猜你喜欢

Dataloader的使用

How to do the performance pressure test of "Health Code"

I also gave you the MySQL interview questions of Boda factory. If you need to come in and take your own

Sorting out 49 reports of knowledge map industry conference | AI sees the future with wisdom

2022 tea master (intermediate) examination question bank and tea master (intermediate) examination questions and analysis

分布式全局唯一ID解决方案详解

Pytest automated testing - compare robotframework framework
![[pat (basic level) practice] - [simple simulation] 1064 friends](/img/37/0ef0f8aae15ae574be1d76c97497c9.jpg)
[pat (basic level) practice] - [simple simulation] 1064 friends

OdeInt與GPU

神经网络-卷积层
随机推荐
分布式架构系统拆分原则、需求、微服务拆分步骤
软件研发的十大浪费:研发效能的另一面
Cmake selecting compilers and setting compiler options
Odeint et GPU
Use of dataloader
Extension fragment
2022 Shanghai safety officer C certificate examination question simulation examination question bank and answers
Pytest automated testing - compare robotframework framework
Section 27 remote access virtual private network workflow and experimental demonstration
Openresty rewrites the location of 302
Leecode records the number of good segmentation of 1525 strings
【硬十宝典】——1.【基础知识】电源的分类
LM small programmable controller software (based on CoDeSys) note 20: PLC controls stepping motor through driver
pytorch神经网络搭建 模板
LeetCode_58(最后一个单词的长度)
Pytorch(四) —— 可视化工具 Visdom
Announcement on the list of Guangdong famous high-tech products to be selected in 2021
CF1638E. Colorful operations Kodori tree + differential tree array
LeetCode_35(搜索插入位置)
Pytorch(二) —— 激活函数、损失函数及其梯度