以前想用循環來System.in (或是其它輸入方式老是達不預想的效果,第一次輸入后回車,不會接收下一次用戶的輸入)。后來才發現readline() != null才能達到效果。
package net.blogjava.chenlb;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* 重復接收用戶輸入一行命令
* @author chenlb 2008-3-11 下午09:24:50
*/
public class UserInput {
public static void main(String[] args) throws IOException {
System.out.println("說明: 輸入QUIT退出");
System.out.print("\ninput>");
String inputStr = null;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
while((inputStr = br.readLine()) != null) {
if(inputStr.equals("QUIT")) {
System.exit(0);
}
System.out.println("你輸入的是: "+inputStr); //處理你的邏輯
System.out.print("\ninput>");
}
}
}
posted on 2008-03-11 21:49
流浪汗 閱讀(976)
評論(0) 編輯 收藏 所屬分類:
JAVA/J2EE