1. 程式人生 > 實用技巧 >DataInputStream資料位元組專屬輸入流

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(); } } } } }