FilterOutputStream close() in Java

close(): This method is available in the java.io.FilterOutputStream class of Java.

Syntax:

void java.io.FilterOutputStream.close() throws IOException

This method closes this output stream and releases any system resources associated with the stream.

When not already closed, the close method of FilterOutputStream calls its flush method, and then calls the close method of its underlying output stream.

Parameters: NA

Returns: NA

Throws:

IOException - if an I/O error occurs.

Approach

Java

import java.io.File;
import java.io.FileOutputStream;
import java.io.FilterOutputStream;
import java.io.IOException;

public class FilterOutputStreamclose {
    public static void main(String[] args) throws IOException {
        File data = new File("D:\\hello.txt");
        FileOutputStream file = new FileOutputStream(data);
        FilterOutputStream filter = new FilterOutputStream(file);

        System.out.println("Closing the filter output stream");
        filter.close();
    }
}

Output:

Closing the filter output stream


Some other methods of FilterOutputStream

flush()This method flushes this output stream and forces any buffered output bytes to be written out to the stream.

write(byte[])This method writes b.length bytes to this output stream.

write(int)This method writes the specified byte to this output stream.

write(byte[], int, int)This method writes len bytes from the specified byte array starting at offset off to this output stream.


No comments:

Post a Comment