package LyfPractice;
import org.junit.Test;
import java.io.*;
import java.util.Scanner;
/**
* Created by fangjiejie on 2016/12/7.
*/
public class Turn {
public static void main(String[] args) {
//in();
//in1();
in2();
}
//java使用System.in代表标准输入,即键盘输入
//以键盘输入为例介绍转换流
//有死循环不要用单元测试
//常用输入流一
public static void in(){
Scanner cin=new Scanner(System.in);
while(true){
String result=cin.nextLine();
if(result.toUpperCase().equals("Q")){
break;//System.exit(0);//强制中断java虚拟机
}
System.out.println(result);
}
}
//常用输入流二
public static void in1(){
InputStream in=System.in;
while(true){
byte[] buffer=new byte[1024];
try {
in.read(buffer);
if(new String(buffer).trim().toUpperCase().equals("Q")){
break;
}
System.out.println(new String(buffer).trim());
} catch (IOException e) {
e.printStackTrace();
}
}
}
//常见输入流三 字节输入转换成字符输入流
public static void in2(){
//由于Reader无调用方法,所以用
try {
// Reader h1=new InputStreamReader(System.in);
// BufferedReader h2=new BufferedReader(h1);
BufferedReader h =new BufferedReader(new InputStreamReader(System.in));
while(true){
String result=h.readLine();
if(result.trim().toUpperCase().equals("Q")){
break;
}
System.out.println(result);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
java 中的转换流
最新推荐文章于 2023-07-08 16:32:46 发布