Professional Documents
Culture Documents
DEPARTMENT : CSE
Bachelor of Engineering (Computer Science & Engineering)
Java Programing(CST-205)
TOPIC OF PRESENTATION:
2
PipedWriter
The PipedWriter class is used to write java pipe as a stream of characters.
This class is used generally for writing text. Generally PipedWriter is connected to
a PipedReader and used by different threads.
Constructor:
Methods
PipedReader
The PipedReader class is used to read the contents of a pipe as a stream of
characters. This class is used generally to read text.
PipedReader class must be connected to the same PipedWriter and are used by
different threads.
Constructor:
Example
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());
}
}
}
QUIZ:
a. Writer
b. Reader
c. FileReader
d. FileInputStream
Reference Links:
https://www.geeksforgeeks.org/java-io-pipedreader-class-java/
https://www.geeksforgeeks.org/java-io-pipedwriter-class-java/
https://docs.oracle.com/javase/7/docs/api/java/io/PipedReader.html
https://docs.oracle.com/javase/7/docs/api/java/io/PipedWriter.html
https://www.javatpoint.com/java-pipedwriter-class
https://www.javatpoint.com/java-pipedreader-class
THANK YOU