How can I return to the start of a line in a console?

后端 未结 3 575
故里飘歌
故里飘歌 2020-12-03 06:42

How can I return to the start of a line and overwrite what has already been output on the console? The following does not appear to work:

System.out.print(my         


        
3条回答
  •  自闭症患者
    2020-12-03 07:17

    If you just want to write a new line to the console, you should use the println() method:

    System.out.println(mystuff);
    

    However, this will not delete what is already on the line. Actually, since System.out is a PrintStream, which is a type of OutputStream, that is basically hard to do, although you may find terminal-specific ways to do it.

    You might have better luck using a Java implementation of a curses library, such as JavaCurses.

提交回复
热议问题