Java BufferedReader Read Line readLine(String prompt, boolean force)

Here you can find the source of readLine(String prompt, boolean force)

Description

read Line

License

Open Source License

Declaration

public static String readLine(String prompt, boolean force) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static String readLine(String prompt, boolean force) {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String s = null;//w ww . ja va 2  s  . c o  m

        try {
            System.out.print(prompt + ":");
            System.out.flush();
            s = br.readLine();
            while (force && ((s == null) || (s.trim().length() == 0))) {
                System.out.print(prompt + ":");
                s = br.readLine();
            }
        } catch (IOException ioe) {
            System.out.println("IO error trying to read your name!");
            System.exit(1);
        }
        return s;
    }

    public static String readLine(String prompt) {
        return readLine(prompt, false);
    }
}

Related

  1. readLine(String filepath)
  2. readLine(String filePathAndName, String encoding)
  3. readLine(String fmt, Object... args)
  4. readLine(String path)
  5. readLine(String prompt)
  6. readLine(String s)
  7. readLine(String s)
  8. readLine(String value, BufferedReader procout)
  9. readLineByLine(File file, char[][] terminators, boolean keepTerminators, Consumer readLineListener)