Since the recent study of the content of the actual operation is more, so the new notes to use the code as the main bar!
The main content of this back is input, Java mainly uses scanner class and BufferedReader. Overall not difficult, but some of the details can be summarized, see the code:
Import Java.io.*;import Java.util.scanner;public class Iotest{public static void Main (string[] args) throws exception{// Scanner provides a variety of constructors, different constructors can accept files, input streams, strings as data sources//used to extract parse out basic type values and string values//here system.in represents keyboard input Scanner sc = new Scanner ( system.in);//The default is a space, using the regular table Sc.usedelimiter ("\ n"),//hasnextxxx (), XXX does not write, default feel string//has the next item returns TRUE, but if there is no next item does not necessarily return false, It is also possible to be blocked here for blocking while (Sc.hasnext ()) {//output input string next = Sc.next (); if (Next.equals ("exit") break; SYSTEM.OUT.PRINTLN ("Keyboard input content is" + next);} String s = "Hello cer"; Scanner ss = new Scanner (s);//return here Falsewhile (Ss.hasnext ()) {System.out.println ("The contents of the string are:" +ss.next ());} Always read string object BufferedReader br = new BufferedReader (new InputStreamReader (system.in)); String line = Null;while ((line = Br.readline ()) = null) {System.out.println ("User keyboard input is:" + line);}}
Output Result:
$ Java iotest
Cer
The content of the keyboard input is a CER
Exit
The contents of the string are: Hello
The contents of the string are: CER
Test String
User keyboard input is: Test String
As the gaze writes, the scanner Hasnext () of the keyboard input will be more useful when there is no next token in the block's character.
Java self-injection three-entry