如何实现对象序列化与反序列化的长尾操作?

2026-06-09 17:42:54 920阅读 0评论 SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计223个文字,预计阅读时间需要1分钟。

javaimport java.io.*;

如何实现对象序列化与反序列化的长尾操作?

public class SerializeDemo { public static void main(String[] args) { Employee e=new Employee(); e.name=Reyan Ali; e.address=Phokka Kuan, Ambehta Peer; e.SSN=11122333; e.number=101; try { FileOutputStream fileOut=new FileOutputStream(employee.ser); ObjectOutputStream out=new ObjectOutputStream(fileOut); out.writeObject(e); out.close(); fileOut.close(); System.out.println(Object has been serialized); } catch (IOException i) { i.printStackTrace(); } }}

gistfile1.txt

import java.io.*; public class SerializeDemo { public static void main(String [] args) { Employee e = new Employee(); e.name = "Reyan Ali"; e.address = "Phokka Kuan, Ambehta Peer"; e.SSN = 11122333; e.number = 101; try { FileOutputStream fileOut = new FileOutputStream("/tmp/employee.ser"); ObjectOutputStream out = new ObjectOutputStream(fileOut); out.writeObject(e); out.close(); fileOut.close(); System.out.printf("Serialized data is saved in /tmp/employee.ser"); }catch(IOException i) { i.printStackTrace(); } } } import java.io.*; public class DeserializeDemo { public static void main(String [] args) { Employee e = null; try { FileInputStream fileIn = new FileInputStream("/tmp/employee.ser"); ObjectInputStream in = new ObjectInputStream(fileIn); e = (Employee) in.readObject(); in.close(); fileIn.close(); }catch(IOException i) { i.printStackTrace(); return; }catch(ClassNotFoundException c) { System.out.println("Employee class not found"); c.printStackTrace(); return; } System.out.println("Deserialized Employee..."); System.out.println("Name: " + e.name); System.out.println("Address: " + e.address); System.out.println("SSN: " + e.SSN); System.out.println("Number: " + e.number); } }

如何实现对象序列化与反序列化的长尾操作?

标签:对象序列化及反gistfile1txt

本文共计223个文字,预计阅读时间需要1分钟。

javaimport java.io.*;

public class SerializeDemo { public static void main(String[] args) { Employee e=new Employee(); e.name=Reyan Ali; e.address=Phokka Kuan, Ambehta Peer; e.SSN=11122333; e.number=101; try { FileOutputStream fileOut=new FileOutputStream(employee.ser); ObjectOutputStream out=new ObjectOutputStream(fileOut); out.writeObject(e); out.close(); fileOut.close(); System.out.println(Object has been serialized); } catch (IOException i) { i.printStackTrace(); } }}

gistfile1.txt

import java.io.*; public class SerializeDemo { public static void main(String [] args) { Employee e = new Employee(); e.name = "Reyan Ali"; e.address = "Phokka Kuan, Ambehta Peer"; e.SSN = 11122333; e.number = 101; try { FileOutputStream fileOut = new FileOutputStream("/tmp/employee.ser"); ObjectOutputStream out = new ObjectOutputStream(fileOut); out.writeObject(e); out.close(); fileOut.close(); System.out.printf("Serialized data is saved in /tmp/employee.ser"); }catch(IOException i) { i.printStackTrace(); } } } import java.io.*; public class DeserializeDemo { public static void main(String [] args) { Employee e = null; try { FileInputStream fileIn = new FileInputStream("/tmp/employee.ser"); ObjectInputStream in = new ObjectInputStream(fileIn); e = (Employee) in.readObject(); in.close(); fileIn.close(); }catch(IOException i) { i.printStackTrace(); return; }catch(ClassNotFoundException c) { System.out.println("Employee class not found"); c.printStackTrace(); return; } System.out.println("Deserialized Employee..."); System.out.println("Name: " + e.name); System.out.println("Address: " + e.address); System.out.println("SSN: " + e.SSN); System.out.println("Number: " + e.number); } }

标签:对象序列化及反gistfile1txt