今天是与Nashorn一起玩的第一天。我正在尝试收听console.readLine()的输入。不幸的是,它返回空值。我在做什么错了?
var Console = Packages.java.io.Console;
var Level = Packages.java.util.logging.Level;
var Logger = Packages.java.util.logging.Logger;
var System = Packages.java.lang.System;
var Thread = Packages.java.lang.Thread;
function onStart() {
new Thread(function () {
var logger = Logger.getLogger("com.TestClass");
var console = System.console();
if(console != null){
logger.info("Exists!");
while(true) {
var input = console.readLine();
logger.warning(input);
}
} else {
logger.warning("Does not exist!");
}
}).start();
}