Java tutorial
//package com.java2s; import java.io.Closeable; import java.io.IOException; import java.net.HttpURLConnection; import java.net.URLConnection; import java.util.Scanner; public class Main { public static void close(final Closeable... closeables) { for (Closeable closeable : closeables) { try { if (closeable != null) { closeable.close(); } } catch (IOException ioe) { } } } public static void close(final URLConnection connection) { if (connection instanceof HttpURLConnection) { ((HttpURLConnection) connection).disconnect(); } } public static void close(final Scanner scanner) { if (scanner != null) { scanner.close(); } } }