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
            }

  • 相关阅读:
    【Yom框架】漫谈个人框架的设计之一:是IRepository还是IRepository<T>?
    【NET】Winform用户控件的初步封装之列表页控件
    【C#】Smtp发送邮件
    c# http请求封装
    js 时区转换
    c# http请求接口
    netcore 中间件记录日志
    netcore 调用log4net
    netcore 从api下载文件并直接返回
    netcore 从api下载文件到本地
  • 原文地址:https://www.cnblogs.com/lzhp/p/3773847.html
Copyright © 2011-2022 走看看