其他
Java教程-Java PipedWriter类
整理:Java面试那些事儿
Java PipedWriter类
构造函数
Constructor | Description |
专属福利
方法
Modifier and Type | Method | Method |
示例
import java.io.PipedReader;
import java.io.PipedWriter;
public class PipeReaderExample2 {
public static void main(String[] args) {
try {
final PipedReader read = new PipedReader();
final PipedWriter write = new PipedWriter(read);
Thread readerThread = new Thread(new Runnable() {
public void run() {
try {
int data = read.read();
while (data != -1) {
System.out.print((char) data);
data = read.read();
}
} catch (Exception ex) {
}
}
});
Thread writerThread = new Thread(new Runnable() {
public void run() {
try {
write.write("I love my country\n".toCharArray());
} catch (Exception ex) {
}
}
});
readerThread.start();
writerThread.start();
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
}
I love my country
我就知道你会点赞+“在看”