Java将输出行替换为标准输出 [英] Java replace line of output to standard out

查看:78
本文介绍了Java将输出行替换为标准输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
使用Java在控制台窗口中写入相同的位置

我想知道在Java中是否有一种方法可以替换您输出到终端的输出行,从而可以像进度条/计数器类型的东西那样工作.

I was wondering if theres a way, in java, to replace a line of output you outputted to the terminal, such that you could do like a progress bar/counter type thing.

我想做些类似的事情,在顶部打印出已插入记录1/1000",然后在顶部打印已插入记录2/1000",以便只显示最新的记录.

I'd like to do something akin to printing out "Records inserted 1/1000" and then "Records inserted 2/1000" over the top, replacing it so that only the most recent one shows.

推荐答案

打印\ r字符,该字符将光标置于行首.然后写新行.

Print the \r character, which places the cursor at the beginning of the line. And then write the new line.

public static void main(String[] args) throws InterruptedException {

    System.out.print("test");

    Thread.sleep(3000);

    System.out.print('\r');

    System.out.print("lulz");

}

这篇关于Java将输出行替换为标准输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆