(原文鏈接)http://blog.csdn.net/liuhenghui5201/article/details/8351574
DataOutputStream數據輸出流 將java基本數據類型寫入數據輸出流中。並可以通過數據輸入流DataInputStream將數據讀入。
DataOutputStream類
構造函數:
DataOutputStream(OutputStream out);//創建一個將數據寫入指定輸出流out的數據輸出流。
字段摘要:
int written;//到目前爲止寫入數據流的字節數。
主要方法:
void write(byte[] b,int off,int len);//將byte數組off角標開始的len個字節寫到OutputStream 輸出流對象中。
void write(int b);//將指定字節的最低8位寫入基礎輸出流。
void writeBoolean(boolean b);//將一個boolean值以1-byte形式寫入基本輸出流。
void writeByte(int v);//將一個byte值以1-byte值形式寫入到基本輸出流中。
void writeBytes(String s);//將字符串按字節順序寫入到基本輸出流中。
void writeChar(int v);//將一個char值以2-byte形式寫入到基本輸出流中。先寫入高字節。
void writeInt(int v);//將一個int值以4-byte值形式寫入到輸出流中先寫高字節。
void writeUTF(String str);//以機器無關的的方式用UTF-8修改版將一個字符串寫到基本輸出流。該方法先用writeShort寫入兩個字節表示後面的字節數。
int size();//返回written的當前值。
DataInputStream類
構造方法:DataInputStream(InputStream in);
主要方法:
int read(byte[] b);//從輸入流中讀取一定的字節,存放到緩衝數組b中。返回緩衝區中的總字節數。
int read(byte[] buf,int off,int len);//從輸入流中一次讀入len個字節存放在字節數組中的偏移off個字節及後面位置。
String readUTF();//讀入一個已使用UTF-8修改版格式編碼的字符串
String readLine();
boolean readBoolean;
int readInt();
byte readByte();
char readChar();