package IO; import org.junit.Test; import java.io.*; public class OtherStream { //从键盘输入字符串,当遇到e或者exit退出,其余情况转换成大写 public static void main(String[] args) { BufferedReader br = null; try { InputStreamReader isr = new InputStreamReader(System.in); br = new BufferedReader(isr); while (true){ System.out.println("please input the String: "); String data = br.readLine(); if("e".equalsIgnoreCase(data) || "exit".equalsIgnoreCase(data)){ System.out.println("end the programme"); break; } String upperCase = data.toUpperCase(); System.out.println(upperCase); } } catch (IOException e) { e.printStackTrace(); } finally { if(br != null){ try { br.close(); } catch (IOException e) { e.printStackTrace(); } } } } //数据流 @Test public void test(){ DataOutputStream dos = null; try { dos = new DataOutputStream(new FileOutputStream("data.txt")); dos.writeUTF("hason"); dos.flush(); dos.writeInt(23); dos.flush(); dos.writeBoolean(true); dos.flush(); } catch (IOException e) { e.printStackTrace(); } finally { if(dos != null){ try { dos.close(); } catch (IOException e) { e.printStackTrace(); } } } } }