说一说java当中的Console这个类
首先我们看看API中这个类的方法有哪些
这里的话只要注意一点
我在网上找了很久
public static void main(String[] args) {
Console cons = System.console();
if (cons != null) {
// -------------------------
PrintWriter printWriter = cons.writer();
printWriter.write("input:");
cons.flush();
// -------------------------
String str1 = cons.readLine();
// -------------------------
cons.format("%s", str1);
}
}
上面基本上就是网上所用的方法
注意:Console这个类中的方法在idea中都是不能用的,你想用这个类在控制台上面打印出东西是不行的,你可以试一下,在idea中Console永远是为null