型態 | FileStream (I/O) | DataStream(I/O) | FileRead (W/R) | ObjectStream (OI/OO) |
輸入輸入類型 | byte | 各種型別都行 | char | Object |
因各種IO串流不同,導致有不同結果
可以直接在txt或用字元行是打開閱讀的,用 W/R
有些處理byte用 FileStream ,但未必能在記事本打開直接順利閱讀(除非輸入字串或字元)
DataStream 則是通吃各類別,但一樣未必能在記事本打開中順利閱讀(除非輸入字串或字元)
ObjectStream 比較常用來 輸入輸入類別,也是不錯的一個選項
package iotest;
import java.io.*;
public class DataStream {
public static void main(String[] args) throws Exception {
FileOutputStream fout = new FileOutputStream("./newfolder/file3_dataStream");
DataOutputStream Dout = new DataOutputStream(fout);
int a = 9453;
byte b = 87;
boolean c = false;
Dout.writeInt(a);
Dout.writeByte(b);
Dout.writeBoolean(c);
Dout.flush();
Dout.close();
FileInputStream fin = new FileInputStream("./newfolder/file3_dataStream");
DataInputStream din = new DataInputStream(fin);
System.out.println(din.readInt());
System.out.println(din.readByte());
System.out.println(din.readBoolean());
}
}
@copyright MRcodingRoom
觀看更多文章請點MRcoding筆記
觀看更多文章請點MRcoding筆記