java中的BufferReader

键盘输入的代码
package BufferedReader;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class BufferedReaderDemo {

	public static void main(String[] args) throws IOException {
		// BufferedReader的构造方法是BufferedReader(Reader in)
		//InputStreamReader的构造方法是InputStreamReader(InputStream in) 
		//而System.in是InputStream对象
		BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
		System.out.print("请输入数据:");
		String msg=buf.readLine();//readLine()方法返回的是String
		System.out.println(msg);
		buf.close();
	}

}


//BufferedReader的构造方法是BufferedReader(Reader in)
//InputStreamReader的构造方法是InputStreamReader(InputStream in) 
//而System.in是InputStream对象

你可能感兴趣的:(JAVA)