Java 获取与命令行应用程序中的文本在同一行上的输入

Java 获取与命令行应用程序中的文本在同一行上的输入,java,Java,如何在Java应用程序中获得与命令行相同的输入: 我现在有 private static String input(String msg) { Log.log(Level.INFO, "" + msg + ": "); return null; } public void listen() { while (true) { // Display input message input("\ntest-cli"); //

如何在Java应用程序中获得与命令行相同的输入:

我现在有

private static String input(String msg) {
    Log.log(Level.INFO, "" + msg + ": ");
    return null;
}

public void listen() {
    while (true) {
        // Display input message
        input("\ntest-cli");

        // Gather user input
        String rawInput = scanner.nextLine();

        // Check if the users wishes to quit
        if (rawInput.equals("quit") || rawInput.equals("exit")) {
            break;
        }

        // Gather the raw arguments entered by the user
        String[] rawArgs = rawInput.split("\\s+");

        // Check any command or argument was entered
        if (!rawArgs[0].equals("")) {

            /* Check if debug mode is false, if so then run command in try catch to avoid crashing the application
            if an error is thrown. Otherwise run the command with no safety net */

            if (!debugMode) {
                try {
                    call(rawArgs);
                } catch (ArrayIndexOutOfBoundsException e) {
                    print("Command couldn't execute, perhaps not enough arguments? Try: " + rawArgs[0] + " help");
                } catch (Exception e) {
                    print("Command failed to execute.");
                }
            } else {
                call(rawArgs);
            }
        }
    }
}

static void print(String msg) {
    Log.log(Level.INFO, msg);
}
哪些产出:

test-cli: 
help
如何使其看起来像这样(
rawInput
input
相同的行)


你忘了给我们看
print
方法。您显示的代码不会产生给定的结果,我看不到“test cli”或“help”的任何打印。请创建一个。
print
method addedIs您使用日志库而不只是打印到标准输出的原因是什么?它只是在整个应用程序中普遍使用。您不应该真正使用日志作为输入提示。在
input
中,使用
System.out.print(“+msg+”>”);System.out.flush()
test-cli> help