Java.io.PipedReader.close() Method

Advertisements


Description

The java.io.PipedReader.close() method writes the specified byte to the piped output stream. Implements the write method of OutputStream.

Declaration

Following is the declaration for java.io.PipedReader.close() method

public void close()

Parameters

  • NA

Return Value

This method does not return a value.

Exception

  • IOException -- if an I/O error occurs.

Example

The following example shows the usage of java.io.PipedReader.close() method.

package com.tutorialspoint;

import java.io.*;

public class PipedReaderDemo {

   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());
         }

         // close the reader
         System.out.println("Closing reader...");
         reader.close();
         System.out.println("Reader closed.");


      } catch (IOException ex) {
         ex.printStackTrace();
      }


   }
}

Let us compile and run the above program, this will produce the following result:

F
G
Closing reader...
Reader closed.



Advertisements
Advertisements