java\r 字符在 Eclipse 中不起作用

标签 java loops carriage-return

请告知为什么这不起作用,我相信您可以弄清楚我在这里想做什么:

            while (socketChannel.read(buffer) > 0) {
            buffer.flip();
            fileChannel.write(buffer);
            buffer.clear();
            bigDecimal = bigDecimal.add(kilobyteDecimal);
            System.out.print("\\ \r"+"| \r"+"/ \r"+"-- \r");
        }

期望看到旋转字符,但相反,我在每个打印语句中都得到了一个新行。

非常感谢

最佳答案

我已经成功地做到了我想要的,尽管代码需要稍微改变一下,但这正是我想要的,并且它按预期工作:

public class ProgressDial {

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

    if (args[0].equals("false")) {
        System.out.println("Args = false");
        System.exit(0);
    } else {
        while (args[0].equals("true")) {
            System.out.print("\\");
            Thread.sleep(500);
            System.out.print("\b ");
            System.out.print("\r");
            System.out.print("|");
            Thread.sleep(500);
            System.out.print("\b ");
            System.out.print("\r");
            System.out.print("/");
            Thread.sleep(500);
            System.out.print("\b ");
            System.out.print("\r");
            System.out.print("-");
            Thread.sleep(500);
            System.out.print("\b ");
            System.out.print("\r");
        }
    }
}

}

感谢所有给我建议和想法的人。

关于java\r 字符在 Eclipse 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39658283/

相关文章:

java - for循环条件部分的final关键字

java - 使用 Netbeans 8.0.2 并希望使用 org.apache.commons.io.FileUtils;如何?

WordPress Foreach 只显示一个结果

Python:write.csv 添加额外的回车符

java - 在java中读取换行字符

SVN更新冲突时添加^M?

java - 可以使用 Eclipse 查找所有已弃用的方法调用吗?

java - 通过使用 rhino 或标准内置 javascript 支持在 java 中嵌入 javascript 来在客户端使用 Google channel api?

windows - 批处理脚本循环

python - 使用 python 和 Beautiful Soup 迭代网站页面