The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
April 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

flush problems...

Posted by Mathieu Chiasson on April 02, 2001 at 10:37 AM

I'm having a weird problem... I have this piece of code that writes bytes to a file ( which is a Unix pipe ). To simplify everything, I open a file, write to it, and close it using an FileOutputStream. My problem is when I run that piece of code many time in a row, the output is not consistantly the same. I'm expecting a precise number of bytes in my Pipe, but the size changes... Here's the piece of code causing the problem. I'm running it on a SunOs... I've tried all sort of flush, none worked...

ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream( baos );

dos.write( error.create() );
FileOutputStream fos = new FileOutputStream (ERROR_LOGFILE );
BufferedOutputStream dts = new BufferedOutputStream( fos );
System.err.println("size: " + baos.toByteArray().length );
dts.write( baos.toByteArray() );
dts.flush();
fos.close();



Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us