[英]Print a carriage return in java on windows on console
On my OS X machine, the following line gives me a nice and easy way to track the state of my loops:在我的 OS X 机器上,以下行为我提供了一种跟踪循环状态的好方法:
for (int index = 0; index < 100; index++)
for (int subIndex = index; subIndex < 100; subIndex++)
System.out.print("\r" + index + "/" + subIndex + " ");
But when I try to run the same thing on windows, it prints out newlines instead of a carriage return.但是当我尝试在 Windows 上运行相同的东西时,它会打印出换行符而不是回车符。 How can I achieve the same simple method of tracking the process on windows?
如何实现在 Windows 上跟踪进程的相同简单方法?
I had the statement and it worked in the command prompt我有这个语句,它在命令提示符下工作
System.out.println("This is Java"+'\r'+"That");
and gives me output as并给我输出
That is Java
That means it works perfectly.这意味着它可以完美运行。
Note: I run it in Windows 7 with JDK 7 and simple notepad.注意:我在带有 JDK 7 和简单记事本的 Windows 7 中运行它。
It is the problem of eclipse, it will take \\r as a new line character and will print是eclipse的问题,它会以\\r作为换行符并打印
This is Java
That
as output作为输出
如果您使用的是 Eclipse,则必须在控制台窗口中启用控制字符选项。
By "Windows" you mean cmd.exe
? “Windows”是指
cmd.exe
吗? And you want to overwrite to the line you previously output, right?并且您想覆盖之前输出的行,对吗? Unfortunately I think you need to invoke this Win32 API somehow in order to achieve it
不幸的是,我认为您需要以某种方式调用这个 Win32 API 才能实现它
Maybe other Java gurus can provide better answer ...也许其他 Java 大师可以提供更好的答案......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.