中文字幕一区二区人妻电影,亚洲av无码一区二区乱子伦as ,亚洲精品无码永久在线观看,亚洲成aⅴ人片久青草影院按摩,亚洲黑人巨大videos

Java DataOutputStream類

Java 流(Stream) Java 流(Stream)


數據輸出流允許應用程序以與機器無關方式將Java基本數據類型寫到底層輸出流。

下面的構造方法用來創(chuàng)建數據輸出流對象。

DataOutputStream out = new DataOutputStream(OutputStream  out);

創(chuàng)建對象成功后,可以參照以下列表給出的方法,對流進行寫操作或者其他操作。

序號 方法描述
1 public final void write(byte[] w, int off, int len)throws IOException
將指定字節(jié)數組中從偏移量 off 開始的 len 個字節(jié)寫入此字節(jié)數組輸出流。
2 Public final int write(byte [] b)throws IOException
將指定的字節(jié)寫入此字節(jié)數組輸出流。
3
  1. public final void writeBooolean()throws IOException,
  2. public final void writeByte()throws IOException,
  3. public final void writeShort()throws IOException,
  4. public final void writeInt()throws IOException
這些方法將指定的基本數據類型以字節(jié)的方式寫入到輸出流。
4 Public void flush()throws IOException
??刷新此輸出流并強制寫出所有緩沖的輸出字節(jié)。
5 public final void writeBytes(String s) throws IOException
將字符串以字節(jié)序列寫入到底層的輸出流,字符串中每個字符都按順序寫入,并丟棄其高八位。

實例

下面的例子演示了DataInputStream和DataOutputStream的使用,該例從文本文件test.txt中讀取5行,并轉換成大寫字母,最后保存在另一個文件test1.txt中。

test.tx 文件內容如下:

json1
json2
json3
json4
json5

實例

import java.io.*; public class Test{ public static void main(String args[])throws IOException{ DataInputStream in = new DataInputStream(new FileInputStream("test.txt")); DataOutputStream out = new DataOutputStream(new FileOutputStream("test1.txt")); BufferedReader d = new BufferedReader(new InputStreamReader(in)); String count; while((count = d.readLine()) != null){ String u = count.toUpperCase(); System.out.println(u); out.writeBytes(u + " ,"); } d.close(); out.close(); } }

以上實例編譯運行結果如下:

JSON1
JSON2
JSON3
JSON4
JSON5

Java 流(Stream) Java 流(Stream)

其他擴展