Reputation: 3320
So I want to make a java application which, while running, can run custom commands (not windows commands, commands for my application) from the command line, I can already do it, but I'd like to have a prompt such as >
where you'd type commands, how can I output >
and then remove it when it's time to print something else to that line?
Upvotes: 0
Views: 448
Reputation: 2199
I agree with PaoloVictor's recommendation of using Console
, but if you're more curious about architecture I might suggest a REPL (Read, Evaluate, Print Loop). Where you would do something like this.
init();
while(1){
System.out.print("myProgram>");
String cmd = Console.readLine(String fmt, Object... args);
evaluate(cmd);
}
Upvotes: 1
Reputation: 1306
On Java 6, you can use the Console
class for that. Specifically, the readLine
method. From the API:
public String readLine(String fmt, Object... args)
Provides a formatted prompt, then reads a single line of text from the console.
Upvotes: 6