User user=new User();
user.setId("bonnie");
user.setAge("10");
//Object转byte[]
ByteArrayOutputStream byteArrayOutputStream =new ByteArrayOutputStream();
ObjectOutputStream objectOutputStream=new ObjectOutputStream(byteArrayOutputStream);
objectOutputStream.writeObject(user);
byte[] bytes=byteArrayOutputStream.toByteArray(); //byte[]转Object
ByteArrayInputStream byteArrayInputStream=new ByteArrayInputStream(bytes);
ObjectInputStream objectInputStream=new ObjectInputStream(byteArrayInputStream);
User user1=(User)objectInputStream.readObject();
System.out.println(user1);

Object与byte[]互转的更多相关文章

  1. object与byte[]的相互转换、文件与byte数组相互转换

    转载自   https://blog.csdn.net/scimence/article/details/52233656 object与byte[]互转 /// <summary> // ...

  2. 对像转成 和 byte 互转类库方法

    using System; using System.IO; using System.Runtime.Serialization; using System.Runtime.Serializatio ...

  3. 字符串string和内存流MemoryStream及比特数组byte[]互转

    原文:字符串string和内存流MemoryStream及比特数组byte[]互转   字符串string和内存流MemoryStream及比特数组byte[]互转比较 定义string变量为str, ...

  4. 【C#】Switch datatype between object and byte[]

    This sample shows how to turn object to byte[], as well as turn byte[] to object. So,I can turn any ...

  5. Go语言网络通信---string与int互转,int64与[]byte互转,int直接互转,string与[]byte互转

    string与int互转 #string到int int,err:=strconv.Atoi(string) #string到int64 int64, err := strconv.ParseInt( ...

  6. file与 byte[] 互转

    byte 转file String filepath="D:\\"+getName();          File file=new File(filepath);        ...

  7. C# String 与 byte 互转

    String转换为byte数组用byte[] arr = System.Text.Encoding.Default.GetBytes("abcde") byte数组转换为Strin ...

  8. String Byte 互转

    string类型转成byte[]: byte[] byteArray = System.Text.Encoding.Default.GetBytes ( str ); byte[]转成string: ...

  9. golang struct 和 byte互转

    相比于encoding, 使用unsafe性能更高 type MyStruct struct { A int B int } var sizeOfMyStruct = int(unsafe.Sizeo ...

随机推荐

  1. 【转载】Linux设备树(Device Tree)机制

    转:Linux设备树(Device Tree)机制   目录 1. 设备树(Device Tree)基本概念及作用2. 设备树的组成和使用 2.1. DTS和DTSI 2.2. DTC 2.3. DT ...

  2. jsplumb 常用事件

    1. jsPlumb.getAllConnections() 获取所有连接线2. jsPlumb.deleteEveryConnection(); 清空所有连接线3. jsPlumb.deleteCo ...

  3. android系统webview使用input实现选择文件并预览

    一般系统的实现方式: 代码实现 <!doctype html> <html> <head> <meta charset="utf-8"&g ...

  4. 插入数据失败提示: Setting autocommit to false on JDBC Connection 自动提交失败

    来源:https://blog.csdn.net/qq_42799475/article/details/102742109 今天在执行mybstis的测试时,明明已经写好了插入语句但是数据库没有插入 ...

  5. 深入浅出 .NET C# 反射技术

    反射这个词听起来就很牛逼是吧? 嗯的确,反射是比较高级的特性,只有语言基础很扎实的Dev们才应该使用它. 搞点反射,可以提高程序的灵活性.可扩展性.耦合度. 反射这东西,是为了动态地运行时加载,相比于 ...

  6. Windows2008R2 一键安全优化脚本

      ::author vim ::QQ 82996821 ::filename Windows2008R2_safe_auto_set.bat   :start @echo off color 0a ...

  7. #6041. 「雅礼集训 2017 Day7」事情的相似度 [set启发式合并+树状数组扫描线]

    SAM 两个前缀的最长后缀等价于两个点的 \(len_{lca}\) , 题目转化为求 \(l \leq x , y \leq r\) , \(max\{len_{lca(x,y)}\}\) // p ...

  8. 如何在Mac电脑上隐藏视频文件?

    我们都有一些秘密视频,我们只想保留在Mac,iPhone或iPad上.为了完全安全地在Mac上隐藏视频文件,我们提供了两种种最简单的方法.下面就来看一下,如何在Mac上隐藏私密视频文件? 在iTune ...

  9. 使用IDA pro逆向ARM M系核心的Bin固件

    使用IDA pro逆向ARM M系核心的Bin固件 ​ 物联网和智能设备这两年还是比较火的,我们的手中或多或少都有了几个智能设备,比如手环,智能手表,或者门锁什么之类的东西,但是同学们在做逆向的时候, ...

  10. ssh 或 putty 连接linux报错解决方法

    由于当天多次输入错误密码,ssh和putty就连接不上了,纠结了很久解决问题 ssh连接提示错误:server unexpectedly closed network connection putty ...