"Java" console input section

Source: Internet
Author: User

BufferedReader

The most basic method to get data from the System.in input stream

BufferedReader br = new BufferedReader (new InputStreamReader (system.in)); try {    System.out.println (Br.readline ()) ;} catch (IOException e) {    e.printstacktrace ();}
Scanner
Scanner sc = new Scanner (system.in); System.out.println (Sc.nextline ());
Console

Java6 New

Console console = System.Console (), if (console! = null) {    System.out.println (Console.ReadLine ());}
Description
    1. Console is primarily designed to facilitate the interaction of the program with the user, but there is a limitation of the need to use the system comes with the console to run the program, if used in the IDE, there is a great possibility to get the console.

    2. Another feature of the console is the ability to hide passwords:

      Console console = System.Console (), if (console! = null) {    System.out.println (Console.readpassword ());}

      This will not see the password entered by the user, but there is no way to display the user's input as "*" or other characters

    3. Scanner convenient to convert the user's input to the corresponding Java type, in addition, scanner input source is not limited to system.in, but also can be other input source.

"Java" console input section

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.