Java standard output stream, standard error output stream, standard input stream, and scanner

Source: Internet
Author: User

 PackageCom.mydemo.controller;ImportJava.util.Scanner; Public classHelloWorld { Public Static voidMain (string[] args) {System.err.println ("HelloWorld"); System.out.println ("HelloWorld");        System.out.println (system.in);        System.out.println (System.out);                System.out.println (System.err); Scanner Scanner=NewScanner (system.in); String nextline=Scanner.nextline (); }}

Operation Result:

HelloWorld Helloworld[email protected][email Protected][email protected]

How to block the scanner:

1  PackageCom.mydemo.controller;2 3 ImportJava.util.Scanner;4 5  Public classHelloWorld {6      Public Static voidMain (string[] args) {7@SuppressWarnings ("Resource")8Scanner Scanner =NewScanner (system.in);//This line breaks the point9String nextline =Scanner.nextline (); This line breaks.Ten System.out.println (nextline); This line breaks. One     } A}

Debug Run:

Until the 9th line, press F6 will not go down, the console input will go down.

So the nextline () of the scanner object is a blocking method.

Java standard output stream, standard error output stream, standard input stream, and scanner

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.