void write(byte[] b, int off, int len)
描述 (Description)
java.io.PipedOutputStream.write(byte[] b, int off, int len)方法将从offset off开始的指定字节数组中的len个字节写入此管道输出流。 此方法将阻塞,直到所有字节都写入输出流。
声明 (Declaration)
以下是java.io.PipedOutputStream.write()方法的声明。
public void write(byte[] b, int off, int len)
参数 (Parameters)
b - 数据。
off - 数据中的起始偏移量。
len - 要写入的字节数。
返回值 (Return Value)
此方法不返回值。
异常 (Exception)
IOException - 如果发生I/O错误。
例子 (Example)
以下示例显示了java.io.PipedOutputStream.write()方法的用法。
package com.iowiki;
import java.io.*;
public class PipedOutputStreamDemo extends PipedInputStream {
public static void main(String[] args) {
byte[] b = {'h', 'e', 'l', 'l', 'o'};
// create a new Piped input and Output Stream
PipedOutputStream out = new PipedOutputStream();
PipedInputStreamDemo in = new PipedInputStreamDemo();
try {
// connect input and output
out.connect(in);
// write something
out.write(b, 0, 3);
// flush the stream
out.flush();
// print what we wrote
for (int i = 0; i < 3; i++) {
System.out.print("" + (char) in.read());
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
让我们编译并运行上面的程序,这将产生以下结果 -
hel