Pause the program to wait for the user to enter a String and press enter. - Java Native OS

Java examples for Native OS:Shell Command

Description

Pause the program to wait for the user to enter a String and press enter.

Demo Code


//package com.java2s;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    /**//  w  w  w. j  ava 2 s  . com
     * Pause the program to wait for the user to enter a String
     * and press enter.
     * @return String the user entered
     */
    public static String waitForReadStringAndEnterKeyPress() {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(
                    System.in));
            String s = br.readLine();
            return s;
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        }
        return null;
    }
}

Related Tutorials