zoukankan      html  css  js  c++  java
  • Java IO操作

    一、File类

    File f=new File(“文件名”);

    可以通过f来操作f相关的行为。

    二、IO流

    如果想实现数据的输入输出,肯定需要使用stream;

    其中输出流InputStream和Reader作为基类,输出流OutputStream和Writer作为基类。他们都是抽象基类。

    字节流 Stream

    字符流 R/W

    image

    java序列化

    在C#是使用Serializable标签就可以了,在java中是需要实现java.io.Serializable

    下面的Person类要实现上面的接口,其实上接口没有方法。

    try(ObjectOutputStream oos=new ObjectOutputStream(new FileOutputStream("object.txt"))) {
                Person per=new Person(12,"lzp");
                oos.writeObject(per);
               
                try (ObjectInputStream ois=new ObjectInputStream(new FileInputStream("object.txt"))){
                    Person p=(Person)ois.readObject();
                    System.out.println(p.getAge()+p.getName());
                } catch (Exception e) {
                    // TODO: handle exception
                    e.printStackTrace();
                }
               
               
               
            } catch (Exception e) {
                e.printStackTrace();
                // TODO: handle exception
            }

  • 相关阅读:
    安卓自动化测试添加用例执行回放
    【十二省2019】异或粽子
    【BZOJ4260】Codechef REBXOR
    【JSOI2015】字符串树
    【HAOI2017】供给侧改革
    【NOI2018】你的名字
    【十二省2019】字符串问题
    【LOJ#6041】事情的相似度
    【SP8093】JZPGYZ
    【BZOJ1396】识别子串
  • 原文地址:https://www.cnblogs.com/lzhp/p/3773847.html
Copyright © 2011-2022 走看看