从控制台读取
1.普通读取:Scanner in = new Scanner(System.in)
2.读取密码:Console cons = System.console();
next()与 hasNext() 的区别:
String next() 读取输入的下一个单词,以空格作为分隔符,返回输入的字符串
boolean hasNext() 读取下一个单词,以空格作为判断符,返回检测输入中是否还有其他单词
String nextLine() 读取输入的下一行内容,返回一个字符串
String nextInt(); boolean hasNextInt();
String nextDouble(); boolean hasNextDouble();
格式化输出
System.out.printf("%8.2f",x);
String message = String.format("hello,%s I love you",name);
日期和时间的转化符......
printf 格式符
文件的输入输出
读取:Scanner in = new Scanner(Path.get("D:\\mydirectory\\myfile.txt"),"UTF-8");
写入:PrintWrite out = new PrintWrite("D:/mydirectory/myfile.txt"),"UTF-8");
(上同)地址也可 "D:\\mydirectory\\myfile.txt"),"UTF-8"
了解以下:
Scanner(File f)
Scanner(String Data)
PrintWriter(String fileName)
static Path get(String pathname)