BufferedOutputStream flush() in Java

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

Syntax:

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

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

Parameters: NA

Returns: NA

Throws:

IOException - if an I/O error occurs.

Approach

Java

import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;

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

        FileOutputStream fileOutputStream =
new FileOutputStream("D:\\hello.txt");

        BufferedOutputStream bufferedOutputStream =
new BufferedOutputStream(fileOutputStream);

        bufferedOutputStream.flush();

        System.out.println("Flush Success");

        bufferedOutputStream.close();
    }
}

Output:

Flush Success


No comments:

Post a Comment