Print a carriage return in java on windows on console

后端 未结 3 1371
忘掉有多难
忘掉有多难 2020-12-19 02:03

On my OS X machine, the following line gives me a nice and easy way to track the state of my loops:

for (int index = 0; index < 100; index++)
    for (int         


        
相关标签:
3条回答
  • 2020-12-19 02:52

    By "Windows" you mean cmd.exe? And you want to overwrite to the line you previously output, right? Unfortunately I think you need to invoke this Win32 API somehow in order to achieve it

    • SetConsoleCursorPosition
      • Cf. Calling Win32 API method from Java

    Maybe other Java gurus can provide better answer ...

    0 讨论(0)
  • 2020-12-19 02:53

    I had the statement and it worked in the command prompt

    System.out.println("This is Java"+'\r'+"That");
    

    and gives me output as

    That is Java
    

    That means it works perfectly.

    Note: I run it in Windows 7 with JDK 7 and simple notepad.

    It is the problem of eclipse, it will take \r as a new line character and will print

    This is Java
    That
    

    as output

    0 讨论(0)
  • 2020-12-19 02:56

    If you are on Eclipse, you have to enable the control character option on the Console Window.

    0 讨论(0)
提交回复
热议问题