zoukankan      html  css  js  c++  java
  • DataInputStream数据字节专属输入流

    DataInputStream:数据字节输入流。
    DataOutputStream写的文件,只能用DataInputStream去读。并且读的时候你需要提前知道写入的顺序。
    读的顺序需要和写的顺序一致。才可以正常取出数据。
     
     
    DataInputStream:
    package com.javaSe.DataInputStream;
    
    
    import java.io.DataInputStream;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    
    
    /*
    DataInputStream:数据字节输入流。
    DataOutputStream写的文件,只能用DataInputStream去读。并且读的时候你需要提前知道写入的顺序。
    读的顺序需要和写的顺序一致。才可以正常取出数据。
    */
    public class DataInputStreamTest01 {
        public static void main(String[] args) {
            DataInputStream ds = null;
        
            try {
                ds = new DataInputStream(new FileInputStream("data"));
                byte b = ds.readByte();
                short s = ds.readShort();
                int i = ds.readInt();
                long l = ds.readLong();
                float f = ds.readFloat();
                double d = ds.readDouble();
                boolean bl = ds.readBoolean();
                char c = ds.readChar();
        
                System.out.println(b);
                System.out.println(s);
                System.out.println(i);
                System.out.println(l);
                System.out.println(f);
                System.out.println(d);
                System.out.println(bl);
                System.out.println(c);
                
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                if (ds != null) {
                    try {
                        ds.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
  • 相关阅读:
    #Leetcode# 448. Find All Numbers Disappeared in an Array
    #Leetcode# 65. Valid Number
    #Leetcode# 37. Sudoku Solver
    #Leetcode# 25. Reverse Nodes in k-Group
    POJ 3264 Balanced Lineup
    HDU 3947 Assign the task
    Codeforces Round #546 (Div. 2)
    2019.08.18【NOIP?提高组】模拟 A 组 总结
    jzoj 6307. 安排
    jzoj 6305. 最小值
  • 原文地址:https://www.cnblogs.com/xlwu/p/13466139.html
Copyright © 2011-2022 走看看