import java.util.*;
import java.io.*;
/**
* <p>Title: 標注輸入輸出</p>
* <p>Description: 接收標准的鍵盤輸入,和輸出到屏幕。</p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Filename: standerdIO.java</p>
* @version 1.0
*/
public class standerdIO{
/**
*<br>方法說明:主方法
*<br>輸入參數:
*<br>返回類型:
*/
public static void main(String[] args){
Vector vTemp = new Vector();
boolean flag = true;
while(flag){
System.out.print("input>");
String sTemp ="";
//讀取輸入,System.in表示接收鍵盤輸入流
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
try{
//讀取一行輸入
sTemp = stdin.readLine();
}catch(IOException ie){
System.err.println("IO error!");
}
//解析輸入命令
String sCMD="";
String sContext="";
int point = sTemp.indexOf(":");
if(point==-1){
sCMD = sTemp.trim();
}else{
sCMD = sTemp.substring(0,point);
sContext = sTemp.substring(point+1);
}
//添加數據
if(sCMD.equalsIgnoreCase("in")){
if(sContext.equals("")){
System.err.println("this command format is errer!");
}else{
vTemp.addElement(sContext);
}
}//查看結果
else if(sCMD.equalsIgnoreCase("out")){
for(int i=0;i<vTemp.size();i++){
System.out.println(i+":"+vTemp.elementAt(i));
}
}//結束
else if(sCMD.equalsIgnoreCase("quit")){
flag=false;
}
else{
System.err.println("this command don´t run!");
System.out.print("use: in:command");
System.out.print("use: out");
}
}
}
}