import java.io.*;
public class KeyinTest
{
public static void main(String[] args)
{
BufferedReader br = null;
try
{
//将system.in对象转换成Reader对象
InputStreamReader reader = new InputStreamReader(System.in);
//将普通Reader包装成Buffereader
br = new BufferedReader(reader);
String buffer = null;
//采用循环方式一行一行的读取
while((buffer = br.readLine()) != null)
{
//如果读取的字符串为exit,程序退出
if(buffer.equals("exit"))
{
System.exit(1);
}
//打印读取的内容
System.out.println("输入内容为:" + buffer);
}
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
finally
{
try
{
br.close();
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
}
}
}
初学Java,IO之使用转换流,读取键盘输入(四十三)
最新推荐文章于 2020-11-23 21:00:09 发布