I am reading and writing from console created by running my application from a batch file.
I am creating a small servlet and I am running into the problem that while I am typing, things are printed (such as things like clients connecting or disconnecting) on the end of where I am typing. It basically makes everything look funny and I have been trying to find a way to copy what I was typing, print out what occurred (ie. Client x connects!) in its place and paste the command I was typing below so that I can continue.
I think I got a part of it working (the part where what I was typing is replaced), but I cannot think of a way to copy what I was typing or put it on the next line so that I can continue typing to it.
This method is called whenever anything is to be printed out, it basically puts the time stamp on the output.
public void say(String s){
Calendar calendar = Calendar.getInstance();
Date now = calendar.getTime();
Timestamp current = new Timestamp(now.getTime());
SimpleDateFormat date = new SimpleDateFormat("HH:mm:ss");
String time = date.format(current);
//how it gets printed
System.out.println("\r" + time + "> " + s);
}
The thread I am using to wait for input:
Thread thread = new Thread(){
public void run(){
Scanner scan = new Scanner(System.in);
while(scan.hasNextLine()){
String s = scan.nextLine();
//do something with s?
}
}
};
thread.start();
Any help would be greatly appreciated!