当前位置:网站首页>对象的序列化与反序列化
对象的序列化与反序列化
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 + '\'' +
'}';
}
}
边栏推荐
- OdeInt與GPU
- Talk about testdeploy
- Solve the problem that the external chain file of Qiankun sub application cannot be obtained
- Announcement on the list of Guangdong famous high-tech products to be selected in 2021
- 【硬十宝典】——1.【基础知识】电源的分类
- STM32 extended key scan
- Kodori tree board
- LM小型可编程控制器软件(基于CoDeSys)笔记二十:plc通过驱动器控制步进电机
- Summary of acl2021 information extraction related papers
- 解决:拖动xib控件到代码文件中,报错setValue:forUndefinedKey:this class is not key value coding-compliant for the key
猜你喜欢
Pytest automated testing - compare robotframework framework
常用的Transforms中的方法
Dual contractual learning: text classification via label aware data augmentation reading notes
C#读写应用程序配置文件App.exe.config,并在界面上显示
Dual Contrastive Learning: Text Classification via Label-Aware Data Augmentation 阅读笔记
Odeint and GPU
[2020 overview] overview of link prediction based on knowledge map embedding
2022 G2 power station boiler stoker examination question bank and G2 power station boiler stoker simulation examination question bank
解决:Thread 1:[<*>setValue:forUndefinedKey]:this class is not key value coding-compliant for the key *
Extension fragment
随机推荐
All in all, the low code still needs to solve these four problems
Registration for R2 mobile pressure vessel filling test in 2022 and R2 mobile pressure vessel filling free test questions
Tencent has five years of testing experience. It came to the interview to ask for 30K, and saw the so-called software testing ceiling
Shell之分析服务器日志命令集锦
神经网络-卷积层
2022 hoisting machinery command registration examination and hoisting machinery command examination registration
常用的Transforms中的方法
STM32 photoresistor sensor & two channel AD acquisition
Overview of the construction details of Meizhou veterinary laboratory
2022 a special equipment related management (elevator) simulation test and a special equipment related management (elevator) certificate examination
【硬十宝典目录】——转载自“硬件十万个为什么”(持续更新中~~)
Codeforces Round #771 (Div. 2) ABCD|E
解决:Thread 1:[<*>setValue:forUndefinedKey]:this class is not key value coding-compliant for the key *
VR线上展览所具备应用及特色
Day 52 - tree problem
LeetCode_66(加一)
手动实现一个简单的栈
2022 tea master (intermediate) examination question bank and tea master (intermediate) examination questions and analysis
Pytorch(三) —— 函数优化
STM32 光敏电阻传感器&两路AD采集