Java Console flush() Example

Console class flush() method example. This example shows you how to use flush() method.


Syntax is : public void flush()
This method flushes the console and forces any buffered output to be written immediately.

Here is the code.

/**
 * @(#) FlushConsole.java
 * A class representing use of method flush() of Console class in 
java.io Package.
 * @Version  11-June-2008
 @author   Rose India Team
 */
import java.io.*;

public class FlushConsole {

    public static void main(String[] args) {

        //Create a console object.
        Console objConsole = System.console();
        if (objConsole != null) {
            String userName = objConsole.readLine("Enter  username  : ");
            System.out.println("You have entered : " + userName);
        }
        // flush method call.
        objConsole.flush();
    }
}

Output of the program.
Enter  username  : mahendra
You have entered : mahendra

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US