覆盖以前的控制台输出 [英] Override previous Console Output

查看:120
本文介绍了覆盖以前的控制台输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以覆盖最后的 System.out.println 输出,因此我可以例如显示数组中的更改或创建progessbar?

is it possible to override the last System.out.println output, so i can for example visualize changes in a array or create a progessbar?

例如,如果我有这个类:

For example if i have this class:

class Main{
  public static void main(String[] args){
    for(int i = 0; i < 10; i++){
      for(int j = 0; j < i; j++){
        System.out.print("#");
      }
      System.out.println("");
    }
  }
}

创建这个简单的progressbar显示在一行而不是在10个单独的行?

What do i have to do to create this simple progressbar which is shown in a single line and not in 10 seperate lines?

推荐答案

(Windows),但它不是非常便携...

This works on my particular console (Windows) but it's not terribly portable...

public class Test {
    public static void main(String[] args) throws Exception {
        for (int i = 0; i < 100; i++) {
            System.out.print("#");
            if (i % 20 == 0) {
                System.out.print("\r                    \r");
            }
            System.out.flush();
            Thread.sleep(100);
        }
    }
}

=http://docs.oracle.com/javase/7/docs/api/java/io/Console.html =nofollow> 控制台 类,但实际上不是真的买你非常多,因为我看到...

There's also the Console class, but that doesn't actually buy you very much as far as I can see...

这篇关于覆盖以前的控制台输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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