Java BufferedReader Read Line readLine(String fmt, Object... args)

Here you can find the source of readLine(String fmt, Object... args)

Description

read Line

License

Open Source License

Declaration

public static String readLine(String fmt, Object... args) 

Method Source Code


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

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

public class Main {
    public static String readLine() {
        java.io.Console console = System.console();

        if (console != null) {
            return System.console().readLine();
        } else {/*from  w w w  .j a  v a 2  s  .  c  o  m*/
            try {
                BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
                return buffer.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e.getMessage());
            }
        }
    }

    public static String readLine(String fmt, Object... args) {
        java.io.Console console = System.console();

        if (console != null) {
            return System.console().readLine(fmt, args);
        } else {
            print(fmt, args);
            try {
                BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
                return buffer.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e.getMessage());
            }
        }
    }

    public static void print(String text, Object... args) {
        printf(System.out, text, args);
    }

    public static void printf(PrintStream stream, String text, Object... args) {
        stream.printf(text, args);
    }
}

Related

  1. readLine(String fileName)
  2. readLine(String fileName)
  3. readLine(String filename, String encoding)
  4. readLine(String filepath)
  5. readLine(String filePathAndName, String encoding)
  6. readLine(String path)
  7. readLine(String prompt)
  8. readLine(String prompt, boolean force)
  9. readLine(String s)