DataOutputStream size() in Java

size(): This method is available in the java.io.DataOutputStream class of Java.

Syntax:

int java.io.DataOutputStream.size()

This method returns the current value of the counter written, and the number of bytes written to this data output stream so far.

Note:

If the counter overflows, it will be wrapped to Integer.MAX_VALUE.

Parameters: NA

Returns: the value of the written field.

Exceptions: NA

Approach

Java

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

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

        FileOutputStream file =
new FileOutputStream("D:\\hello.txt");
        DataOutputStream data = new DataOutputStream(file);

        System.out.println(data.size());
        data.close();

    }
}

Output:

0


No comments:

Post a Comment