Formatter flush() in Java

flush(): This method is available in java.util.Formatter class of Java.

Syntax:

void java.util.Formatter.flush()

This method flushes this formatted.

Note: Flushing a formatter writes any buffered output in the destination to the underlying stream.

Parameters: NA

Returns: NA

Throws:

FormatterClosedException - If this formatter has been closed by invoking its close() method

Approach

Java

import java.util.Formatter;
import java.util.Locale;

public class Formatterflush {
    public static void main(String[] args) {

        StringBuffer buffer = new StringBuffer();

        Formatter formatter = new Formatter(buffer, Locale.UK);
        formatter.format("Hello %s ", "Java");

        formatter.flush();

        System.out.println(formatter);

    }
}

Output:

Hello Java 


No comments:

Post a Comment