Java_基础—两种方式实现键盘录入
package com.soar.otherio;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
public class Demo7_SystemIn {
/*
* 两种方式实现键盘录入:
****** A:BufferedReader的readLine方法。
* BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
****** B:Scanner
*/
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); //InputStreamReader转换流
String line = br.readLine(); //123
System.out.println(line); //123
br.close();
Scanner sc = new Scanner(System.in);
String line2 = sc.nextLine(); //abc
System.out.println(line); //abc
sc.close();
}
}