Java Console flush()方法

java.io.Console.flush() 用于刷新控制台。

1 语法

public void flush()

2 参数

3 返回值

4 示例 

package com.yiidian;

/**
 * 一点教程网: http://www.yiidian.com
 */
/**
 * java.io.Console.flush()法的例子
 */
import java.io.Console;

public class Demo {
    public static void main(String[] args) {
        Console cnsl = null;

        try {
            //Create a console object.
            cnsl = System.console();

            // test for console not null
            if (cnsl != null) {

                // read line from the console
                String name = cnsl.readLine("Enter  name  : ");

                // print
                System.out.println("You have entered : " + name);
            }

            // flushes console and forces output to be written
            cnsl.flush();

        } catch(Exception ex) {
            // if any error occurs
            ex.printStackTrace();
        }
    }
}

输出结果为:

You have entered : yiidian

热门文章

优秀文章