2011年8月24日

JAVA輸出時刷新同一行的方式

我是用\b也許有更好的方式,不過還要在研究研究
for(int i=0;i<100;i++) {
	String str = String.format("%1$-40s","Reading... ") + i + "%";
	System.out.print(str);
	try {
		Thread.sleep(100);
	} catch (InterruptedException e) {
		e.printStackTrace();
	}
	if (!str.isEmpty()) {
		for(int j=0;j>str.length();j++) {
			System.out.print("\b");
			
		}
	}
}

沒有留言:

張貼留言