Java DataOutputStream.size()

Syntax

DataOutputStream.size() has the following syntax.

public final int size()

Example

In the following code shows how to use DataOutputStream.size() method.


/*from ww  w  .  j  ava  2  s .  co m*/

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

public class Main {
  public static void main(String[] args) throws IOException {

    byte[] buf = { 12, 11, 22, 33, 44 };

    FileOutputStream fos = new FileOutputStream("c:/test.txt");
    DataOutputStream dos = new DataOutputStream(fos);

    int size = 0;

    for (byte b : buf) {
      dos.write(b);
      size = dos.size();
      System.out.print("Size: " + size + "; ");
    }
  }
}