DataOutputStream Size() Example
Returns the current value of the counter written
DataOutputStreamclass Size() method example. This example shows you how to use Size() method.This method Returns the current value of the counter written, the number of bytes written to this data output stream so far.
Here is the code:-
/**
* @Program that Returns the current value of the counter written, the number
of bytes written to this data output stream so far.
* Size.java
* Author:-RoseIndia Team
* Date:-09-jun-2008
*/
import java.io.*;
public class Size {
public static void main(String[] args)throws IOException {
byte[]b={1,2,3,4,5};
FileOutputStream fos=new FileOutputStream("g.txt");
DataOutputStream dos=new DataOutputStream(fos);
//Writes len bytes from the specified byte array starting at offset
dos.write(b,2,b.length-2);
//Returns the current value of the counter written
int i=dos.size();
FileInputStream fis=new FileInputStream("g.txt");
DataInputStream dis=new DataInputStream(fis);
System.out.println("Bytes to be written out to the stream: "+dis.read(b));
System.out.println("The current value of the counter written is :"+i);
}
} |
Output of the Program
| Bytes to be written out to the stream: 3 |
|