FileDocCategorySizeDatePackage
CountingOutExample.javaAPI DocExample1718Wed May 18 09:39:00 BST 2005com.discursive.jccook.io

CountingOutExample

public class CountingOutExample extends Object

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

		new CountingOutExample().start();
	
public voidstart()


		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" );
		}