读取输入
Scanner in = new Scanner(System.in);
Stirng name = in.nextLine();
其中,使用nextLine方法是因为在输入行中有可能包含空格。要想读取一个单词,就调用
Stirng name = in.next();
要想读取一个整数,就调用nextInt方法
String name = in.nextInt();
文件输入与输出
读取文件
Scanner in = new Scanner(Paths.get("niyflle.txt"), "UTF-8");
如果文件名中包含反斜杠符号,就要记住在每个反斜杠之前再加一个额外的反斜杠:
“ c:\\mydirectory\\myfile.txt ”
写入文件
需要构造一个 PrintWriter 对象
PrintWriter out = new PrintlulriterC'myfile.txt", "UTF-8");