我正在編寫命令行java應用程序並計劃使用庫來解析命令行選項。 我想將多個文件名作爲輸入。如何獲取命令行中的多個源文件java應用程序
現在我已經選擇了apache commons-cli(1.2)。 我的主要方法如下
public static void main(String[] args) {
Options options = new Options();
options.addOption("s", "source", true, "file(s) as input");
CommandLineParser parser = new GnuParser();
CommandLine input = null;
try{
input = parser.parse(options, args);
}catch (ParseException e){
new HelpFormatter().printHelp("Usage: ", options);
System.exit(1);
}
String [] files = null;
if(input.hasOption("s")){
files = input.getOptionValues("s");
}
}
現在,當我執行與參數"-s /home/keshava/file1 /home/keshava/file2"
我得到的文件數組只有一個文件的程序。
我知道我可以通過"-s /home/keshava/file1 -s /home/keshava/file2"
得到多個文件但我不想這樣做。
有沒有辦法以任何方式指定值分隔符? 任何其他圖書館的建議也可以。
感謝, Keshava
它是2105使用像[JewelCLI](http://jewelcli.lexicalscope.com/)或至少[JSAP](http://www.martiansoftware.com/jsap/)這樣的現代參數解析器, apache commons廢話就是那些廢話總是隨着時間的流逝而變得更加棘手。 –