Java Stream Close close(Closeable resource, File file)

Here you can find the source of close(Closeable resource, File file)

Description

Close the given I/O resource of the given file.

License

Open Source License

Parameter

Parameter Description
resource The I/O resource to be closed.
file The I/O resource's subject.

Declaration

private static void close(Closeable resource, File file) 

Method Source Code

//package com.java2s;
/*/*from w  w w . j a v a2s . 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.

                e.printStackTrace();
            }
        }
    }
}

Related

  1. close(Closeable closeable, Logger logger)
  2. close(Closeable io, Logger logger)
  3. close(Closeable resource)
  4. close(Closeable resource)
  5. close(Closeable resource)
  6. close(Closeable stream)
  7. close(Closeable... streams)
  8. close(Collection inCloseables)
  9. close(DataOutputStream out)