1、分析参数
args = new String[5];
args[0]="d:/3-20.sql";
args[1]="-date";
args[2]="2013-01-01";
args[3]="-date1";
args[4]="2013-11-11";
讲参数分析后键值对成对放入map中()如果第一个参数包含‘-’作为键,下一个就是作为value
package com.hiveF;
import java.util.HashMap;
import java.util.Map;
public class ParseArgs {
private Map map = null;
public ParseArgs(String[] args) {
map = new HashMap() ;
if (args.length == 0) {
return ;
}
int i = 0;
while(i < args.length){
String par = args[i].trim();
if (par.startsWith("-")) {
String key = par.substring(1).trim();
i ++ ;
String value = null;
if (args.length>i) {
value = args[i].trim();
if (value.startsWith("\"") || value.startsWith("\'")) {
value = value.substring(1,value.length() - 1).trim();
}
}
map.put(key, value);
i ++ ;
}else {
i ++ ;
}
}
}
public Map getMap() {
return map;
}
}
2、拿到sql语句
public static String getSql(File file) throw