Attempts to flush the given output stream, and then closes it. - Android File Input Output

Android examples for File Input Output:OutputStream

Description

Attempts to flush the given output stream, and then closes it.

Demo Code

/*//from w  ww . j  a v a  2 s. com
 * Copyright (C) 2010 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
//package com.java2s;

import java.io.IOException;

import java.io.OutputStream;

public class Main {
    /**
     * Attempts to flush the given output stream, and then closes it.
     *
     * @param outStream the {@link java.io.OutputStream}. No action taken if outStream is null.
     */
    public static void flushAndCloseStream(OutputStream outStream) {
        if (outStream != null) {
            try {
                outStream.flush();
            } catch (IOException e) {
                // ignore
            }
            try {
                outStream.close();
            } catch (IOException e) {
                // ignore
            }
        }
    }
}

Related Tutorials