看一下该站点,它解释了两种使用java中的控制台读取的方法,使用
Scanner或使用
InputStreamReaderSystem.in中的经典方法。
以下代码摘自引用的网站:
import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;public class ReadConsoleSystem { public static void main(String[] args) { System.out.println("Enter something here : "); try{ BufferedReader bufferRead = new BufferedReader(new InputStreamReader(System.in)); String s = bufferRead.readLine(); System.out.println(s); } catch(IOException e) { e.printStackTrace(); } }}-
import java.util.Scanner;public class ReadConsoleScanner { public static void main(String[] args) { System.out.println("Enter something here : "); String sWhatever; Scanner scanIn = new Scanner(System.in); sWhatever = scanIn.nextLine(); scanIn.close(); System.out.println(sWhatever); }}问候。



