InputStreamReader close Example

InputStreamReader class close example. This example shows you how to use close method.


InputStreamReader class close example.public void close() throws IOExceptionCloses the stream and releases any system resources associated with it. Once the stream has been closed, further read(), ready(), mark(), reset(), or skip() invocations will throw an IOException. Closing a previously closed stream has no effect.

Here is the code

/**
 * @ # Close.java
 * A class repersenting use to close method 
 * of InputStreamReader class in java.io package
 * version 28 May 2008
 * author Rose India 
 */
import java.io.*;

public class Close {

    public static void main(String args[]) throws Exception {

        File file = new File("text.txt");

        if (!file.exists()) {
            System.out.println("File not found");
            System.exit(1);
        }

        FileInputStream fis = new FileInputStream(file);
        InputStreamReader isr = new InputStreamReader(fis);

        System.out.println("Text from file ");

        //Reads a single character.
        System.out.println(isr.read());

        //Closes the stream
        isr.close();
    }
}

Output
 This data is read through the program

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US