1. 程式人生 > 其它 >Java常用工具類之IO流工具類

Java常用工具類之IO流工具類

package com.wazn.learn.util;


import java.io.Closeable;
import java.io.IOException;
 
/**
 * IO流工具類
 * 
 * @author yangzhenyu
 * 
 */
public class IOUtil {
    /**
     * 關閉一個或多個流物件
     * 
     * @param closeables
     *            可關閉的流物件列表
     * @throws IOException
     */
    public static void close(Closeable... closeables) throws IOException {
        if (closeables != null) {
            for (Closeable closeable : closeables) {
                if (closeable != null) {
                    closeable.close();
                }
            }
        }
    }
 
    /**
     * 關閉一個或多個流物件
     * 
     * @param closeables
     *            可關閉的流物件列表
     */
    public static void closeQuietly(Closeable... closeables) {
        try {
            close(closeables);
        } catch (IOException e) {
            // do nothing
        }
    }
 
}