8、使用转换流处理标准输入
1 package Io; 2 3 import java.io.BufferedReader; 4 import java.io.IOException; 5 import java.io.InputStreamReader; 6 7 public class TestSystem { 8 public static void main(String[] args) { 9 BufferedReader br = null; 10 // 把字节流转为字符流 11 try { 12 br = new BufferedReader(new InputStreamReader(System.in)); 13 String str = null; 14 while ((str = br.readLine()) != null) { 15 if (str.equals("exit")) 16 break; 17 System.out.println(str); 18 } 19 } catch (Exception e) { 20 e.printStackTrace(); 21 } finally { 22 try { 23 if (br != null) 24 br.close(); 25 } catch (IOException e) { 26 e.printStackTrace(); 27 } 28 } 29 } 30 }