Java self-study notes (3) -- Input

Source: Internet
Author: User

Java self-study notes (3) -- Input
Because I have learned a lot of practical operations recently, I suggest using code as the subject for new notes!

The main content of this response is input, and the callback class and BufferedReader are mainly used in Java. In general, it is not difficult, but some details can be summarized, look at the Code:

Import java. io. *; import java. util. optional; public class ioTest {public static void main (String [] args) throws Exception {// delimiter provides a variety of constructors, different constructors can use files, input streams, and strings as data sources. // These constructors extract and parse basic type values and string values. // here System. in indicates that keyboard input SC = new keyboard (System. in); // The default value is space, and the regular expression SC is used. useDelimiter ("\ n"); // hasNextXxx (), when xxx is not written, the default value is string // returns true if there is another one, however, if there is no next item, false is not necessarily returned, and it may be blocked. Here it is blocked while (SC. hasNext () {// output input String next = SC. next (); I F (next. equals ("exit") break; System. out. println ("the keyboard input is" + next);} String s = "hello cer"; kernel ss = new kernel (s); // falsewhile (ss. hasNext () {System. out. println ("the content of the string is:" + ss. next ();} // always read the String object BufferedReader br = new BufferedReader (new InputStreamReader (System. in); String line = null; while (line = br. readLine ())! = Null) {System. out. println ("User keyboard input:" + line );}}}

Output result:

$ Java ioTest
Cer
The content entered by the keyboard is cer.
Exit
The content of the string is: hello
The content of the string is: cer
Test String
User keyboard input: test String


Just as the annotation is written, the hasNext () of the token input on the keyboard will block the feature when there is no next token, which is more practical.

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.