Java.io.CharArrayReader.close() Method



Description

The java.io.CharArrayReader.close() method closes character array reader and releases any system resources associated with it.

Declaration

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

public void close()

Parameters

NA

Return Value

The method doesn't return any value.

Exception

NA

Example

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

package com.tutorialspoint;

import java.io.CharArrayReader;
import java.io.IOException;

public class CharArrayReaderDemo {
   public static void main(String[] args) {      CharArrayReader car = null;
      char[] ch = {'H', 'E', 'L', 'L', 'O'};

      try {
         // create new character array reader
         car = new CharArrayReader(ch);
         
         // closes the character array stream
         car.close();
         
         // read the character array stream
         car.read();
                  
      } catch(IOException e) {
         // if I/O error occurs
         System.out.print("Stream is already closed");
      } finally {
         // releases any system resources associated with the stream
         if(car!=null)
            car.close();
      }
   }
}

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

Stream is already closed
java_io_chararrayreader.htm
Advertisements