当前位置:网站首页>对象的序列化与反序列化
对象的序列化与反序列化
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 + '\'' +
'}';
}
}边栏推荐
- RuntimeError: “max_pool2d“ not implemented for ‘Long‘
- js解决浮点数相乘精度丢失问题
- 常用的Transforms中的方法
- RuntimeError: “max_pool2d“ not implemented for ‘Long‘
- LeetCode_ 53 (maximum subarray and)
- 2022 tea master (intermediate) examination question bank and tea master (intermediate) examination questions and analysis
- C read / write application configuration file app exe. Config and display it on the interface
- AssertionError assert I.ndim == 4 and I.shape[1] == 3
- 【硬十宝典】——1.【基础知识】电源的分类
- LM小型可编程控制器软件(基于CoDeSys)笔记十九:报错does not match the profile of the target
猜你喜欢

Introduction to JVM stack and heap

Pytorch convolution operation

2022 G2 power station boiler stoker examination question bank and G2 power station boiler stoker simulation examination question bank

Daily algorithm & interview questions, 28 days of special training in large factories - the 13th day (array)

Ten wastes of software research and development: the other side of research and development efficiency

2022.2.7-2.13 AI industry weekly (issue 84): family responsibilities

Basic skeleton of neural network nn Use of moudle

解决:拖动xib控件到代码文件中,报错setValue:forUndefinedKey:this class is not key value coding-compliant for the key

Registration of P cylinder filling examination in 2022 and analysis of P cylinder filling

Use of dataloader
随机推荐
[FTP] the solution to "227 entering passive mode" during FTP connection
[difficult] sqlserver2008r2, can you recover only some files when recovering the database?
JS rotation chart
C - detailed explanation of operators and summary of use cases
先有网络模型的使用及修改
OdeInt与GPU
Common interview questions ①
Odeint and GPU
C#读写应用程序配置文件App.exe.config,并在界面上显示
Dede collection plug-in does not need to write rules
测量三相永磁同步电机的交轴直轴电感
Shell之分析服务器日志命令集锦
Introduction to JVM stack and heap
The junior college students were angry for 32 days, four rounds of interviews, five hours of soul torture, and won Ali's offer with tears
About the transmission pipeline of stage in spark
分布式-总结列表
Talk about testdeploy
Odeint et GPU
Common UNIX Operation and maintenance commands of shell
Research on medical knowledge atlas question answering system (I)