Java Stream Close close(File file)

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

Description

Use this to close a File that has been opened by this Application

License

Open Source License

Parameter

Parameter Description
file The Desired File to close using Java API

Return

Whether or not the File was successfully closed

Declaration

public static boolean close(File file) 

Method Source Code

//package com.java2s;
/**/*from w  w  w  .  jav a2s  .co  m*/
 * Copyright (c) 2013, Robert Cherry * All rights reserved.
 *
 * This file is part of the Faust Engine.
 *
 * The Faust Engine is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option) any
 * later version.
 *
 * The Faust Engine 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 General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * the Faust Engine. If not, see <http://www.gnu.org/licenses/>.
 */

import java.io.File;
import java.io.FileInputStream;

import java.io.IOException;

public class Main {
    /**
     * Use this to close a File that has been opened by this Application
     *
     * @param file The Desired File to close using Java API
     * @return Whether or not the File was successfully closed
     */
    public static boolean close(File file) {

        // Do not take null files
        if (file != null) {

            // Try - catch statement (IOException)
            try {

                // (Final) Input stream for the File
                final FileInputStream fis = new FileInputStream(file);

                // Close the channel that Java uses to communicate with the File
                fis.getChannel().close();

                // Successfully close File
                return true;
            } catch (IOException ioe) {

                // This File was not successfully closed
                return false;
            }
        }

        // This File was not successfully closed.
        return false;
    }
}

Related

  1. close(Closeable resource, File file)
  2. close(Closeable stream)
  3. close(Closeable... streams)
  4. close(Collection inCloseables)
  5. close(DataOutputStream out)
  6. close(FileReader fr)
  7. close(FileReader reader, BufferedReader br)
  8. close(final Closeable resource, final String resourceId)
  9. close(final Exception e, final Closeable... objects)