• Post Reply Bookmark Topic Watch Topic
  • New Topic

need a help for printing value in console...  RSS feed

 
sridhar Ranganathan
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
see the below program...

try
{
for(int i=1;i<=10;i++)
{
System.out.print(i);
Thread.sleep(1000);
}
} catch(InterruptedException ie )
{

}

Output :12345678910
I need the output 1,2,3 etc...same position in console....
ie) 1 will hide then 2 will appear the same place like that...
(overwrite)
can you please help me the same....

Thanks & Regards,
Sridhar.R
 
Campbell Ritchie
Marshal
Posts: 56541
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tried the \b escape on Windows and it didn't work, but printing

System.out.print("\b");

works nicely on my bash shell (Linux).
 
shiva shankar
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may need to do sort of 'cls' in console and that will involve JNI call. Here is a related thread, but the logic doesnt seem to work for me
http://forum.java.sun.com/thread.jsp?forum=31&thread=55931
 
Campbell Ritchie
Marshal
Posts: 56541
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by shiva shankar:
You may need to do sort of 'cls' in console and that will involve JNI call. Here is a related thread, but the logic doesnt seem to work for me
http://forum.java.sun.com/thread.jsp?forum=31&thread=55931
You can't use Runtime.exec() to invoke "cls" can you? I know there are some such instructions which cannot be invoked from Runtime.exec().

I couldn't get the quoted link to open: please would you check it.
 
shiva shankar
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's the right link

http://forums.sun.com/thread.jspa?messageID=942414
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Campbell Ritchie:
You can't use Runtime.exec() to invoke "cls" can you? I know there are some such instructions which cannot be invoked from Runtime.exec().

cls is a built-in command from cmd.exe, which means that you need to call it using "cmd.exe /c cls". However, this creates a new cmd session (window), and will not cls the current screen.
 
Gamini Sirisena
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This works for me on my windows 2000 box..


[ September 16, 2008: Message edited by: Gamini Sirisena ]
 
Campbell Ritchie
Marshal
Posts: 56541
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since then, I have tried something very similar on Windows Vista, and it worked nicely. It might only be on older versions of Windows (eg Win9x) that it wouldn't work.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!