package com.io; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import org.junit.Test; /* * 标准输出流 System.out 返回outStream * * 标准输入流 System.in 返回inputStream */ public class 标准输入输出流 { /* * 从控制台输入字符串,把字符串转换为大写,直至输入e或exit退出 */ @Test public void systemInOutTest() { BufferedReader br = null; try { InputStream is = System.in; InputStreamReader isr = new InputStreamReader(is, "GBK");// 需要把字节流转成字符流 br = new BufferedReader(isr); String str; while (true) { str = br.readLine(); if ("e".equalsIgnoreCase(str) || "exit".equalsIgnoreCase(str)) { break; } System.out.println(str.toUpperCase()); } } catch (IOException e) { e.printStackTrace(); } finally { try { br.close(); } catch (IOException e) { e.printStackTrace(); } } } }
时间: 2024-10-25 21:12:12