zoukankan      html  css  js  c++  java
  • 四套读写方案

    第一套:字节流读取写入方案

    FileInputStream :字节流方式读取文本文件

    FileOutputStream:字节流写入硬盘

    第二套:字符流读取写入方案

    FileReader:字符流读取文本

    FileWriter:字符流写入文本

    BufferedReader:自定义缓存大小,读取文本 8192个char

    BufferedWriter:写入文本

    一般和FileReader和FileWriter结合使用

    第四套:可以读取二进制(img图片等 )

    DataInputStream:将本地的img加载到内存中

    DataOutputStream::将内存中的二进制数据写入到硬盘上的某个文件中。

    序列化和反序列化:

    //序列化
            List<Dog> list=new ArrayList<Dog>();
            list.add(new Dog("豆豆",15));
            list.add(new Dog("豆豆2",15));
            F 
            ObjectOutputStream oos=new ObjectOutputStream(fos);
            oos.writeObject(list);
            fos.close();
            oos.close();
            System.out.println("序列化成功!");
     反序列化
     FileInputStream fis=new FileInputStream("save.bin");
            ObjectInputStream ois=new ObjectInputStream(fis);
            List<Dog> list=(List<Dog>)ois.readObject();
            for (Dog dog : list) {
                System.out.println(dog.getName());
    }
    注意点:
    01.如果自定义类需要被序列化,那么必须实现Serializable接口
    02.禁止某个属性被序列化
    使用transient修饰
    比如:
    transient public String msg
  • 相关阅读:
    2020-12
    知识的深度跟知识的广度
    限额类费用报销单N+1原则
    用友实习总结
    NC57,NC63-NC二开经验总结
    union和union all的区别
    2020
    mark_rabbitMQ
    营销之路
    怎么对ORACLE里的CLOB字段进行模糊查询
  • 原文地址:https://www.cnblogs.com/myhome-1/p/5563776.html
Copyright © 2011-2022 走看看