2016-09-23 39 views
1

工作,請告知這是爲什麼不工作,我相信你能找出什麼,我想在這裏做的:的java r字符不是在Eclipse

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

期待看到旋轉的角色,而是我在每一份印刷聲明中都會有新的一行。

非常感謝

+0

你想展示哪種圖案? –

+1

'\ r'是返回的字符,你可以嘗試'\\ r'來轉義'\\',但我不確定你想要做什麼。 –

+0

@JornVernee嗨,我試圖模仿舊的太陽微系統撥號... 我試過使用\ b也回去一個字符,以便它看起來像旋轉停止\/- – gcclinux

回答

0

我已經成功地做到我想要的東西,雖然代碼已經改變了一下這正是我想要的,它按預期工作:

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

}

感謝大家給我的建議和想法。

+0

它適用於我沒有回車 – Bohemian