DataInputStream
生活随笔
收集整理的這篇文章主要介紹了
DataInputStream
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
DataInputStream和DataOutputStream是對流的修飾,對流添加自己的格式
<span style="white-space:pre"> </span>DataOutputStream dbos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("t")));dbos.writeInt(2);dbos.writeUTF("userid");dbos.writeUTF("param");dbos.flush();dbos.close();DataInputStream dbis = new DataInputStream(new BufferedInputStream(new FileInputStream("t")));System.out.println(dbis.readInt());System.out.println(dbis.readUTF());System.out.println(dbis.readUTF());dbis.close();調用一次writeXXX,就寫入的是字節長度和字節
對應的readXXX就是根據字節長度讀取字節流
BufferedReader(new InputStreamReader(dbis)) 是不行的,因為InputStreamReader需要知道dbis字節流的編碼,而這種編碼是其特有的,所有不能正確解碼
總結
以上是生活随笔為你收集整理的DataInputStream的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: shell 编程中空格的使用,双引号,单
- 下一篇: ByteArrayOutputStrea