java:I/O 根据用户输入反馈信息

import java.io.*;
class userInputIO{
            //Java中成员变量有默认初始化,也就是如果不显式设置初始值的话就会被初始化为其类型的默认值(0、false、null等)。 
        private BufferedReader bufferedReader;
        public userInputIO(){
            //System.in用户的输入做成BufferedReader流
            bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        }
        public String getInputLine(){
            String inputLine = null;
            try {
                inputLine = bufferedReader.readLine(); //用户输入数据之后,按下回车键,该行代码即可读取到用户的输入
            } catch (IOException e) {
                e.printStackTrace();
            }
            return inputLine;
        }
        

}

 

public class Test {
    public static void main(String[] args) {
        userInputIO userInputIO =new userInputIO();
        while(true){
            String input = userInputIO.getInputLine();
            System.out.println(input);
        }

    }

}

 

posted @ 2014-06-10 10:38  tinyphp  Views(536)  Comments(0Edit  收藏  举报