OutputStream: flush() : OutputStream « java.io « Java by API






OutputStream: flush()

  
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class Main {
  public static void main(String args[]) throws IOException {
    int howMany = 20;
    // To avoid resizing the buffer, calculate the size of the
    // byte array in advance.
    ByteArrayOutputStream bout = new ByteArrayOutputStream(howMany * 4);
    DataOutputStream dout = new DataOutputStream(bout);

    for (int i = 0; i <= 20; i++) {
      dout.writeInt(i);
    }

    FileOutputStream fout = new FileOutputStream("fibonacci.dat");
    try {
      bout.writeTo(fout);
      fout.flush();
    } finally {
      fout.close();
    }
  }
}

   
    
  








Related examples in the same category

1.extends OutputStream
2.OutputStream: close()
3.OutputStream: write(byte byteValue)
4.OutputStream: write(byte[] values)
5.OutputStream: write(byte[] b, int off, int len)