File test = new File( "test.dat" );
CountingOutputStream countStream = null;
try {
FileOutputStream fos = new FileOutputStream( test );
countStream = new CountingOutputStream( fos );
countStream.write( "Hello".getBytes() );
} catch( IOException ioe ) {
System.out.println( "Error writing bytes to file." );
} finally {
IOUtils.closeQuietly( countStream );
}
if( countStream != null ) {
int bytesWritten = countStream.getCount();
System.out.println( "Wrote " + bytesWritten + " bytes to test.dat" );
}