管道是不同线程之间直接传输数据的基本手段。一个线程A通过它的输出管道发送数据,另一个线程
B把自己的输入管道接到A的输出管道上即可接收到A发送的数据。
[color=blue]v1、PipedInputStream类和PipedOutputStream类
vPipedInputStream类创建的对象称为一个输入管道,PipedOutputStream类创建的对象称为一个输[/color]
出管道。输出管道与输入管道连接就形成了一个传输数据的通道。使用注意的管道,用户可以在不
同线程之间实现数据共享。
4、PipedInputStream类的一些方法
public int read()从管道输入流中读取一字节。字节值被作为0~255之间的一个整数返回,到
达流的末尾返回-1。
public int read(byte b[],int off,int len)
public void connect(PipedOutputStream a)
colse()关闭流
5、PipedOutputStream类的方法
voidclose() Closes this piped output stream and releases any system resources
associated with this stream.
written out.
starting at offset off to this piped output stream.
B把自己的输入管道接到A的输出管道上即可接收到A发送的数据。
[color=blue]v1、PipedInputStream类和PipedOutputStream类
vPipedInputStream类创建的对象称为一个输入管道,PipedOutputStream类创建的对象称为一个输[/color]
出管道。输出管道与输入管道连接就形成了一个传输数据的通道。使用注意的管道,用户可以在不
同线程之间实现数据共享。
v2、PipedInputStream类的构造方法
v ( () 1)PipedInputStream
v (2)PipedInputStream(PipedOutputStream a)
v3、PipedOutputStream类的构造方法
v (1)PipedOutputStream()
v (2)PipedOutputStream(PipedInputStream a)
4、PipedInputStream类的一些方法
public int read()从管道输入流中读取一字节。字节值被作为0~255之间的一个整数返回,到
达流的末尾返回-1。
public int read(byte b[],int off,int len)
public void connect(PipedOutputStream a)
colse()关闭流
5、PipedOutputStream类的方法
voidclose() Closes this piped output stream and releases any system resources
associated with this stream.
void connect(PipedInputStream snk)
output Connects this piped stream to a receiver. voidflush()
Flushes this output stream and forces any buffered output bytes to be written out.
void write(byte[] b, int off, int len)
Writes len bytes from the specified byte array starting at offset off to this piped output stream.
void write(int b)
Writes the specified byte to the piped output stream.