Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: markspace <-@.> Newsgroups: comp.lang.java.help Subject: Re: TeeOutputStream? Date: Mon, 06 Jun 2011 14:08:03 -0700 Organization: A noiseless patient Spider Lines: 24 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Mon, 6 Jun 2011 21:08:05 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="hpGRkhWunYQR6KaCc4QJ3w"; logging-data="23519"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+z844+fgf03BzeHYHiEB0W9HGYscTPoRc=" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10 In-Reply-To: Cancel-Lock: sha1:CuzDjsjmuPTFg+cIbO//2ERohT0= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.help:751 On 6/4/2011 5:17 PM, Knute Johnson wrote: > public void close() throws IOException { > try { > os1.close(); > } finally { > os2.close(); > } > } I've got into the habit of using a utility method like this (untested): public void closeAll( Closeable... closeList ) { for( Closeable c : closeList ) { if( c != null ) { try { c.close() } catch( IOException ex ) { // log... } } } Note that this also checks for null. Your close code conceivably could also throw an NPE. I didn't show any exception chaining here, add it as you like.