The finally block is a key tool for preventing resource leaks.

When closing a file or otherwise recovering resources, place the code in a finally block to ensure that resource is always recovered.

finally {
    if (printWriter != null) { 
        System.out.println("Closing PrintWriter");
        out.close(); 
    } else { 
        System.out.println("PrintWriter not open");
    } 
Post a Comment

Featured Post

Updated Coupons / promo codes for Google Apps for Work / Business

To redeem: 1. Sign up for Google Apps   2. Go to your billing settings  3. Choose your payment plan  4. Enter your promo code ...