Java tutorial
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.Reader; import java.io.Writer; public class Main { public static void closeQuietly(InputStream inputStream) { if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { e.printStackTrace(); } finally { inputStream = null; } } } public static void closeQuietly(OutputStream outputStream) { if (outputStream != null) { try { outputStream.close(); } catch (IOException e) { e.printStackTrace(); } finally { outputStream = null; } } } public static void closeQuietly(Reader reader) { if (reader != null) { try { reader.close(); } catch (IOException e) { e.printStackTrace(); } finally { reader = null; } } } public static void closeQuietly(Writer writer) { if (writer != null) { try { writer.close(); } catch (IOException e) { e.printStackTrace(); } finally { writer = null; } } } }