import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Vector;
/**
* <p>
* Title: 标准输入输出
* </p>
* <p>
* Description: 接收标准的键盘输入,和输出到屏幕。
* </p>
* <p>
* Filename: StanderdIO.java
* </p>
*/
public class StanderdIO {
//获取键盘输入的字符
public static String getInput() {
String input = "";
// 读取输入,System.in表示接收键盘输入流
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
try { // 读取一行用户键盘(Standerd input)输入
input = stdin.readLine();// 注意:readLine方法阻塞当前线程
} catch (IOException ie) {
ie.printStackTrace();
}
return input;
}
public static void main(String[] args) {
Vector vTemp = new Vector();
boolean flag = true;
while (flag) {
System.out.print("input>");
String sTemp = getInput();
// 解析输入命令字符串
String sCMD = "";
String sContext = "";
int point = sTemp.indexOf(":"); // 冒号的下标
if (point == -1) { // 没有冒号
sCMD = sTemp.trim();
} else {
sCMD = sTemp.substring(0, point); // 不包括位置 point,取 in
sContext = sTemp.substring(point + 1); // 取冒号后面的内容
}
// 添加数据到向量vTemp
if (sCMD.equalsIgnoreCase("in")) { // 忽略大小写
if (sContext.equals("")) {
System.err.println("This command format is error!");
} else {
vTemp.addElement(sContext);
}
}
// 查看命令输入历史记录(遍历向量vTemp,并输出到标准输出设备(屏幕))
else if (sCMD.equalsIgnoreCase("out")) {
for (int i = 0; i < vTemp.size(); i++) {
// Returns the component at the specified index.
System.out.println((i + 1) + ":" + vTemp.elementAt(i));
}
}
//退出
else if (sCMD.equalsIgnoreCase("quit")) {
flag = false;
}
else {
System.out.println("This command don't run!");
System.out.println("use: in:command");
System.out.println("use: out");
System.out.println("use: quit");
}
}
}
}
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Vector;
/**
* <p>
* Title: 标准输入输出
* </p>
* <p>
* Description: 接收标准的键盘输入,和输出到屏幕。
* </p>
* <p>
* Filename: StanderdIO.java
* </p>
*/
public class StanderdIO {
//获取键盘输入的字符
public static String getInput() {
String input = "";
// 读取输入,System.in表示接收键盘输入流
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
try { // 读取一行用户键盘(Standerd input)输入
input = stdin.readLine();// 注意:readLine方法阻塞当前线程
} catch (IOException ie) {
ie.printStackTrace();
}
return input;
}
public static void main(String[] args) {
Vector vTemp = new Vector();
boolean flag = true;
while (flag) {
System.out.print("input>");
String sTemp = getInput();
// 解析输入命令字符串
String sCMD = "";
String sContext = "";
int point = sTemp.indexOf(":"); // 冒号的下标
if (point == -1) { // 没有冒号
sCMD = sTemp.trim();
} else {
sCMD = sTemp.substring(0, point); // 不包括位置 point,取 in
sContext = sTemp.substring(point + 1); // 取冒号后面的内容
}
// 添加数据到向量vTemp
if (sCMD.equalsIgnoreCase("in")) { // 忽略大小写
if (sContext.equals("")) {
System.err.println("This command format is error!");
} else {
vTemp.addElement(sContext);
}
}
// 查看命令输入历史记录(遍历向量vTemp,并输出到标准输出设备(屏幕))
else if (sCMD.equalsIgnoreCase("out")) {
for (int i = 0; i < vTemp.size(); i++) {
// Returns the component at the specified index.
System.out.println((i + 1) + ":" + vTemp.elementAt(i));
}
}
//退出
else if (sCMD.equalsIgnoreCase("quit")) {
flag = false;
}
else {
System.out.println("This command don't run!");
System.out.println("use: in:command");
System.out.println("use: out");
System.out.println("use: quit");
}
}
}
}