Search code examples
javaloopscarriage-return

java \r character not working in Eclipse


Please advise why this is not working, I am sure you can figure out what I am trying to do here:

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

expecting to see rotating characters but instead I am getting a new line in every print statement.

Many Thanks


Solution

  • I have managed to do what I wanted, although the code has to change a bit this is exactly what i wanted and it works as expected:

    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");
            }
        }
    }
    

    }

    Thanks to everyone that give me advice and ideas.