package com.atguigu.java;
import org.junit.Test;
import java.io.*;
import java.util.Locale;
public class OtherStreamTest {
//在单元测试方法中无法使用控制台输入字符串
@Test
public void test1(){
BufferedReader br = null;
try {
InputStreamReader isr = new InputStreamReader(System.in);
br = new BufferedReader(isr);
while (true){
String data=br.readLine();
if (data.equalsIgnoreCase("e")||data.equalsIgnoreCase("exit")){
System.out.println("程序退出");
break;
}else{
String upperCase = data.toUpperCase(Locale.ROOT);
System.out.println(upperCase);
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (br!=null){
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
@Test
public void test2() throws IOException {
//1.
DataOutputStream dos = new DataOutputStream(new FileOutputStream("data.txt"));
//2.
dos.writeUTF("浙江大学");
dos.flush();//刷新操作,将内存中数据写入文件
dos.writeInt(23);
dos.flush();
dos.writeBoolean(true);
dos.flush();
//3.
dos.close();
}
@Test
public void test3() throws IOException {
//1.
DataInputStream dis = new DataInputStream(new FileInputStream("data.txt"));
//2.
String name = dis.readUTF();
int age = dis.readInt();
boolean isMale = dis.readBoolean();
System.out.println("name="+name);
System.out.println("age="+age);
System.out.println("isMale="+isMale);
//3.
dis.close();
}
}