2010年5月2日 星期日

Shell Command Read Sample

* If you like to write a shell like command you sholud following two step:
1. Read the System input
2. Parse the command


// System in method
InputStreamReader input = new InputStreamReader(System.in);
BufferedReader reader = new BufferedReader(input);
String line;

while( true ) {
System.out.println(usage);
line = reader.readLine();
String[] token = line.split("\\s"); // token the string


for (int i = 0; i < token.length; i++) { // parse command line
System.out.println(token[i]);
}


} // end while

沒有留言:

張貼留言