Here you can find the source of close(Closeable resource)
Parameter | Description |
---|---|
resource | The I/O resource to be closed. |
public static void close(Closeable resource)
//package com.java2s; /*/*ww w .ja va 2 s .c o m*/ * net/balusc/util/FileUtil.java * * Copyright (C) 2007 BalusC * * This program is free software: you can redistribute it and/or modify it under the terms of the * GNU Lesser General Public License as published by the Free Software Foundation, either version 3 * of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with this library. * If not, see <http://www.gnu.org/licenses/>. */ import java.io.Closeable; import java.io.File; import java.io.IOException; public class Main { /** * Close the given I/O resource of the given file. * @param resource The I/O resource to be closed. * @param file The I/O resource's subject. */ private static void close(Closeable resource, File file) { if (resource != null) { try { resource.close(); } catch (IOException e) { String message = "Closing file " + file.getPath() + " failed."; // Do your thing with the exception and the message. Print it, log it or mail it. System.err.println(message); e.printStackTrace(); } } } /** * Close the given I/O resource. * @param resource The I/O resource to be closed. */ public static void close(Closeable resource) { if (resource != null) { try { resource.close(); } catch (IOException e) { System.err.println("Closing resource failed!"); e.printStackTrace(); } } } }