zoukankan      html  css  js  c++  java
  • 数据流操作示例(DataInputStream和DataOutputStream)

    数据流目的,操作基本变量和String类型进行持久化操作
    import java.io.*;

    /**
    * @auto dh
    * @create 2020-04-24-17:34
    */
    public class File006 {
    public static void main(String[] args) {
    DataOutputStream ds = null;
    DataInputStream di = null;
    try {
    ds = new DataOutputStream(new FileOutputStream("D:" + File.separator + "ac.txt"));
    di = new DataInputStream(new FileInputStream("D:" + File.separator + "ac.txt"));
    ds.writeUTF("张无忌");
    ds.write(24);
    String name=di.readUTF();
    int age=di.read();
    System.out.println("name: "+name);
    System.out.println("age: "+age);
    } catch (FileNotFoundException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    } finally {
    if (ds != null) {
    try {
    ds.close();
    } catch (IOException e) {
    e.printStackTrace();
    }
    }
    if(di!=null){
    try {
    di.close();
    } catch (IOException e) {
    e.printStackTrace();
    }
    }
    }
    }
    }
  • 相关阅读:
    Linux常用命令大全详解
    C++语言关键字及注解
    求两数的最大公约数
    ICOP完成端口详解
    C/C++常见面试题
    猴子吃桃问题之《C语言经典案例分析》
    DTD
    DTD
    DTD的使用
    Rust
  • 原文地址:https://www.cnblogs.com/kukai/p/12769049.html
Copyright © 2011-2022 走看看