C的getopt的就不说了,java中也有类似的东西。需要一个JAR包

http://www.urbanophile.com/arenn/hacking/download.html

简单例程

  1. public static void main(String[] args) { 
  2.  
  3.   args = new String[]{"-a""1" }; 
  4.   gnu.getopt.Getopt getopt = new Getopt("app", args, "a:"); 
  5.   int c = getopt.getopt(); 
  6.   switch (c){ 
  7.   case 'a'
  8.       System.out.println("a:" + getopt.getOptarg()); 
  9.       break
  10.   default
  11.       System.out.println(c); 
  12.   } 
  13.  } 

输出:

a:1