java\r字符在Eclipse中不工作
请告知为什么这不起作用,我相信您可以了解我在这里尝试做什么:java\r字符在Eclipse中不工作,java,loops,carriage-return,Java,Loops,Carriage Return,请告知为什么这不起作用,我相信您可以了解我在这里尝试做什么: while (socketChannel.read(buffer) > 0) { buffer.flip(); fileChannel.write(buffer); buffer.clear(); bigDecimal = bigDecimal.add(kilobyteDecimal);
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");
}
}
}
}
感谢所有给我建议和想法的人。你想展示哪种图案?
\r
是返回的字符,你可以尝试\\r
来逃避“但我不确定你想做什么”。@Jornverne嗨,我正在试着模仿旧的Sun微系统拨号。。。我尝试使用\b同时返回一个字符,使其看起来像是在停止时旋转\|/--在哪里执行程序?在Eclipse/IDE中还是在终端/控制台中?@Robert,我在Eclipse和控制台中都试过了,结果总是一样的。它对我有效,没有回车符