import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Demonstrates what happens when you close the outermost connected stream.
 * 
 * @author Sara Sprenkle
 */
public class ClosingStreams {

	public static void main(String[] args) {
		try {
			FileInputStream fis = new FileInputStream("myfile.dat");

			BufferedReader br = new BufferedReader(new InputStreamReader(fis));
			br.close();

			// calling a reading-related method on the fis stream will throw an exception
			// because the stream is already closed.
			fis.available();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
