System.out.print('\ r')不起作用

时间:2013-07-30 17:26:11

标签: java printing

我的\r因某些奇怪的原因无效。它不会回到行的开头:

char[] animationChars = new char[] {'|', '/', '-', '\\'};

public Main() {

    for (int i = 0; i < 100; i++) {
        System.out.print("Processing: " + i + "% " + animationChars[i % 4] + '\r');

        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}

输出:

Processing: 0% |
Processing: 1% /
Processing: 2% -
Processing: 3% \
Processing: 4% |
Processing: 5% /
Processing: 6% -
Processing: 7% \
Processing: 8% |
Processing: 9% /
Processing: 10% -
Processing: 11% \
Processing: 12% |
Processing: 13% /
Processing: 14% -
Processing: 15% \
Processing: 16% |
Processing: 17% /

1 个答案:

答案 0 :(得分:6)

这是eclipse的问题,它将\ r作为新行字符并将打印一个新行。尝试使用intellij或从命令行提示符。我刚刚在intellij中验证它可以在Windows上运行

I think this bug must still be unresolved