zoukankan      html  css  js  c++  java
  • 【操作基本数据类型的流】

    package test;
    
    import java.io.*;
    
    /**
     * @author shusheng
     * @description 操作基本数据类型的流
     * @Email shusheng@yiji.com
     * @date 2018/12/23 0:08
     */
    public class DataStreamDemo {
        public static void main(String[] args) throws IOException {
            write();
            read();
        }
    
        public static void write() throws IOException {
            //创建输出流对象
            DataOutputStream dos = new DataOutputStream(new FileOutputStream("dos.txt"));
    
            //写数据
            dos.writeByte(10);
            dos.writeBoolean(true);
            dos.writeChar('A');
            dos.writeDouble(1101101.1011110);
            dos.writeFloat((float) 1.023);
            dos.writeShort(123);
            dos.close();
        }
    
        public static void read() throws IOException {
            //创建数据输入流对象
            DataInputStream dis = new DataInputStream(new FileInputStream("dos.txt"));
            byte b = dis.readByte();
            boolean a = dis.readBoolean();
            char c = dis.readChar();
            double d = dis.readDouble();
            float f = dis.readFloat();
            short s = dis.readShort();
            dis.close();
    
            System.out.println(a);
            System.out.println(b);
            System.out.println(c);
            System.out.println(d);
            System.out.println(f);
            System.out.println(s);
    
        }
    }
    终身学习者
  • 相关阅读:
    Java I/O
    iOS AppsFlyer的使用注意事项
    Star Schema and Snowflake Schema
    SSB基准测试
    ES Route
    CPS(Cyber-Physical Systems)白皮书-摘选
    蓄电池放电容量与环境温度的关系
    时间序列分析(二)
    时间序列分析(一)
    IndexR
  • 原文地址:https://www.cnblogs.com/zuixinxian/p/10340667.html
Copyright © 2011-2022 走看看