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();
    }
    }
    }
    }
    }
  • 相关阅读:
    js常见函数使用
    js数组与函数
    移动端响应式布局
    移动开发之rem布局
    移动flex布局
    移动流式布局
    [剑指offer] 矩阵覆盖
    [剑指offer] 变态跳台阶
    [剑指offer] 跳台阶
    [剑指offer] 斐波那契数列
  • 原文地址:https://www.cnblogs.com/kukai/p/12769049.html
Copyright © 2011-2022 走看看