1

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

  • which kind of pattern you want to show ? – Pavneet_Singh Sep 23 '16 at 10:24
  • 1
    `\r` is the character for a return, you can try `\\r` to escape the `\\` but I'm not sure what you're trying to do. – Jorn Vernee Sep 23 '16 at 10:26
  • @JornVernee Hi, I am trying to mimic the old Sun Microsystem dial... I tried using the \b also going back a character so that it looks like rotating on the stop \|/-- –  Sep 23 '16 at 10:51
  • Where do you execute your program? In Eclipse/IDE or in a terminal/console? – Robert Sep 23 '16 at 11:42
  • @Robert, I've tried both in Eclipse and on console and the result is always the same. –  Sep 23 '16 at 12:11
  • Currently noticed that if I remove \r it stays on the same line (great) but I now have a issue adding \b for backspace so that it returns to the start of the line to print out the next character. –  Sep 23 '16 at 12:12

1 Answers1

1

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.