zoukankan      html  css  js  c++  java
  • 关于ByteArrayInputStream、ByteArrayOutputStream 和 ObjectInputStream、ObjectOutputStream

    ByteArrayInputStream  read

    ByteArrayOutputStream   write 

    实现了一个输出流,其中的数据被写入一个 byte 数组。缓冲区会随着数据的不断写入而自动增长。可使用 toByteArray() 和 toString() 获取数据。

    ObjectOutputStream

    package demo;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.ObjectOutputStream;
     
    public class Demo1_ObjectOutputStream {
     
        public static void main(String[] args) throws IOException{
            Student s1=new Student("张三",23);
            Student s2=new Student("李四",24);
            ObjectOutputStream os=new     
                    ObjectOutputStream(new FileOutputStream("record.txt"));
            os.writeObject(s1);
            os.writeObject(s2);
            os.close();
     
        }
     

    ObjectInputStream 

    反序列化流,将之前使用 ObjectOutputStream 序列化的原始数据恢复为对象,以流的方式读取对象。 

     // 创建反序列化流
     FileInputStream fileIn = new FileInputStream("employee.txt");
     ObjectInputStream in = new ObjectInputStream(fileIn);
     // 读取一个对象
     e = (Employee) in.readObject();
  • 相关阅读:
    linux常用的基础知识
    【AW346】走廊泼水节
    【AW355】异象石
    【POJ3417】闇の連鎖
    【APIO2010】巡逻
    【SDOI2011】消防
    【BJWC2010】次小生成树
    【POJ3613】Cow Relays
    【POJ1734】Sightseeing trip
    【POJ1094】Sorting it all out
  • 原文地址:https://www.cnblogs.com/xiongxueqi/p/12584674.html
Copyright © 2011-2022 走看看