import java.io.IOException;
import java.io.FileReader;
import java.io.Reader;

public class FinallyExample {
  public static void doit(String fname) throws IOException {
    Reader r1=null;
    Reader r2=null;
    try {
      r1=new FileReader("/dev/null");
      r2=new FileReader(fname);
      // do some complex stuff on r1 and r2 here
      return;
    }
    finally {
      if (r1!=null) {
	r1.close();
	System.out.println("Closed r1");
      }
      if (r2!=null) {
	r2.close();
	System.out.println("Closed r2");
      }
    }
  }

  public static void main(String[] args) {
    try {
      doit("splat");
    }
    catch (IOException e) {
      System.err.println("Got exception e=" + e);
    }
  }
}
