Javaio learning notes-NLP stream class (1)

Source: Internet
Author: User

1. java. the primary stream class in the io package-BufferedReader and BufferedWriter: BufferedReader: the cached input primary stream; BufferedWriter: the cached output primary stream; InputStreamReader: the input stream that converts bytes to characters; OutputStreamWriter: converts a character to a byte output stream. 2. instance-read characters:

import java.io.BufferedReader;  import java.io.IOException;  import java.io.InputStreamReader;      public class BRRead {        /**      * @param args      * @throws IOException       */      public static void main(String[] args) throws IOException {          // TODO Auto-generated method stub          char c ;          BufferedReader br=new BufferedReader(new InputStreamReader(System.in));          do{              c=(char)br.read();              System.out.println(c);          }while(c!='q');      }    }  

 

By default, System. in is cached by row. That is to say, no input is passed to the application unless you press enter. The read () method is not ideal for interaction. 3. instance-read string:
import java.io.BufferedReader;  import java.io.IOException;  import java.io.InputStreamReader;      public class BRReadLines {        /**      * @param args      * @throws IOException       */      public static void main(String[] args) throws IOException {          // TODO Auto-generated method stub          BufferedReader br=new BufferedReader(new InputStreamReader(System.in));          String string;          do{              string=br.readLine();              System.out.println(string);          }while(!string.equals("stop"));      }    }  

 

The program reads and displays text lines until the user enters the word "stop.

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.