1.普通写法

1
2
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();

2.读取测试文件

1
2
Scanner sc = new Scanner(new FileInputStream("path"));
int n = sc.nextInt();

3.bufferReader加速读写

1
2
BufferedReader bf = new BufferedReader(new InputStreamReader(new FileInputStream("path")));
String s = bf.readLine();