Java PipedReader connect()方法
java.io.PipedReader.connect(PipedWriter src) 方法导致此管道读卡器连接到传送writer src中。如果此对象已经连接到其他某个传送writer,则抛出IOException。
1 语法
public void connect(PipedWriter src)
2 参数
src:要连接的管道编写器。
3 返回值
无
4 示例
package com.yiidian;
/**
* 一点教程网: http://www.yiidian.com
*/
/**
* java.io.PipedReader.connect(PipedWriter src)方法的例子
*/
import java.io.*;
public class Demo {
public static void main(String[] args) {
// create a new Piped writer and reader
PipedWriter writer = new PipedWriter();
PipedReader reader = new PipedReader();
try {
// connect the reader and the writer
reader.connect(writer);
// write something
writer.write(70);
writer.write(71);
// read what we wrote
for (int i = 0; i < 2; i++) {
System.out.println("" + (char) reader.read());
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
输出结果为:
F
G
热门文章
优秀文章