标准输入

System.in 是 InputStream 类型,默认设备是键盘
System.out 是 PrintStream 类型,默认设备是显示器

代码

  1. import java.io.*;
  2. import java.util.Scanner;
  3. public class Main {
  4. public static void main(String[] args) throws Exception {
  5. String path = "./data.txt";
  6. boolean append = false;
  7. // System 类的 public final static InputStream in = null;
  8. // 编译类型 InputStream
  9. // 运行类型 BufferedInputStream
  10. // 表示的是标准输入 键盘
  11. System.out.println(System.in.getClass());
  12. // System 类的 public final static PrintStream out = null;
  13. // 编译类型 PrintStream
  14. // 运行类型 PrintStream
  15. // 表示标准输出 显示器
  16. System.out.println(System.out.getClass());
  17. Scanner scanner = new Scanner(System.in);
  18. System.out.println("请输入内容:");
  19. String next = scanner.next();
  20. System.out.println(next);
  21. }
  22. }