Possible Duplicate:
Using Java, how do I create a console application which manipulates text in system.out?
I have absolutely no idea how to ask this question. I guarantee it’s out there somewhere if one did a Google search (ironic that I don’t know how to search for it).
I know that you can output data in Java. An example would be to use System.out.println. If you wanted to print the update value, use that statement again and it prints a new line with the changed value. I don’t want to keep using print/println every time it changes. That would create a ton of statements. I’m looking for that one line to be refreshed. So say it refreshes every second to display a new value if there is one.
Value of x is: 5
Now, it is constantly refreshing and the number will change if it has been changed (so the number 6 will replace 5 in the exact same location on the screen 5 used to be sitting).
Hopefully I’ve made this clear enough. I went through a Java programming course in college and didn’t see this (not that courses cover every possible angle).
You can’t really do that with Java out-of-the box. The way Java interacts with the console is almost exclusively through streams. You can only ever append stuff to a (non-rewindable) stream, never overwrite or remove from it.
There are a few exceptions in the case of the console, mostly found in the
Consoleclass, which allows a small amount of direct manipulation but doesn’t allow rewriting existing text either.You can do any of those things:
clsorclear, depending on your OS)All but the first option require a medium amount of effort and add considerable complexity to your code, so you should only consider them if that feature is absolutely required.