关闭流方法笔记

public class CloseHelper {
	
	public static void closeStreams(Closeable... streams) throws IOException{
		for(Closeable c:streams){
			if(c!=null){
				c.close();
			}
		}
	}
	
}

 此方法用于关闭常用的inputstream / outputstream 。 可以看出,常用的inputstream / outputstream 都是继承了closeable接口。

传入参数是数组形式,因此需要遍历关闭。

猜你喜欢

转载自vortexchoo.iteye.com/blog/2239850