今天写程序的时候测试了一下,如果在System.in中直接press的是回车,BufferedReader对象的readLine()读取的是什么呢?
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
testInputEnter(System.in);
}
public static void testInputEnter(InputStream in) {
System.out.println("Please press enter now.");
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
String input = null;
try {
input = reader.readLine();
System.out.println("innput == null : " + (input == null));
System.out.println("innput.equals(null) : " + (input.equals(null)));
System.out.println("innput.equals(\\r\\n) : " + (input.equals("\r\n")));
System.out.println("innput.equals(\"\") : " + (input.equals("")));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}