DataOutputStream flush() in Java

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

Syntax:

void java.io.DataOutputStream.flush() throws IOException

This method flushes this data output stream. This forces any buffered output bytes to be written out to the stream.

Parameters: NA

Returns: NA

Throws: IOException - if an I/O error occurs.

Approach

Java

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

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

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

        data.flush();
        System.out.println("successfully flushed");
        data.close();

    }
}

Output:

successfully flushed


No comments:

Post a Comment