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接口。
传入参数是数组形式,因此需要遍历关闭。