集册 Java实例教程 使用InputStream从控制台读取字符行

使用InputStream从控制台读取字符行

欢马劈雪     最近更新时间:2020-01-02 10:19:05

560
使用InputStream从控制台读取字符行
 

import java.io.BufferedReader;

import java.io.IOException;/** 来 自 时代Java - N o w  J a v a . c o m**/

import java.io.InputStreamReader;

 

public class Main {

 

        public static void main(String[] args) {

                 BufferedReader br =

                 new BufferedReader(new InputStreamReader(System.in));

                 

                 String strLine = null;

                 

                 System.out.println("Reading line of characters from console");

                 System.out.println("Enter exit to quit");

                 
                 /*来自 
                  时 代 J     a    v  a - nowjava.com*/

                 try

                 {

                        while( (strLine = br.readLine()) != null)

                        {

                           if(strLine.equals("exit"))

                              break;

                                       

                           System.out.println("Line entered : "  + strLine);

                                                                                                                                                                                                                               

                        }

                       

                        br.close();    
展开阅读全文