下载地址: https://jcenter.bintray.com/org/apache/commons/com.springsource.org.apache.commons.cli/1.2.0/

package com.test;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.BasicParser;
import org.apache.commons.cli.CommandLine; public class Main { public static void main(String[] args) throws Exception {
// Create a Parser
CommandLineParser parser = new BasicParser( );
Options options = new Options( );
options.addOption("h", "help", false, "Print this usage information");
options.addOption("v", "verbose", false, "Print out VERBOSE information" );
options.addOption("f", "file", true, "File to save program output to");
// Parse the program arguments
CommandLine commandLine = parser.parse( options, args );
// Set the appropriate variables based on supplied options
boolean verbose = false;
String file = ""; if( commandLine.hasOption('h') ) {
System.out.println( "Help Message");
System.exit(0);
}
if( commandLine.hasOption('v') ) {
verbose = true;
}
if( commandLine.hasOption('f') ) {
file = commandLine.getOptionValue('f');
} } }

java 解析命令行参数的更多相关文章

  1. java解析命令行参数(common-cli)练习

    package foo; import org.apache.commons.cli.BasicParser; import org.apache.commons.cli.CommandLine; i ...

  2. boost之program_options库,解析命令行参数、读取配置文件

    一.命令行解析 tprogram_options解析命令行参数示例代码: #include <iostream> using namespace std; #include <boo ...

  3. optparse模块解析命令行参数的说明及优化

    一.关于解析命令行参数的方法 关于“解析命令行参数”的方法我们一般都会用到sys.argv跟optparse模块.关于sys.argv,网上有一篇非常优秀的博客已经介绍的很详细了,大家可以去这里参考: ...

  4. python解析命令行参数

    常常需要解析命令行参数,经常忘记,好烦,总结下来吧. 1.Python 中也可以所用 sys 的 sys.argv 来获取命令行参数: sys.argv 是命令行参数列表 参数个数:len(sys.a ...

  5. linux 中解析命令行参数(getopt_long用法)

    linux 中解析命令行参数(getopt_long用法) http://www.educity.cn/linux/518242.html 详细解析命令行的getopt_long()函数 http:/ ...

  6. C语言中使用库函数解析命令行参数

    在编写需要命令行参数的C程序的时候,往往我们需要先解析命令行参数,然后根据这些参数来启动我们的程序. C的库函数中提供了两个函数可以用来帮助我们解析命令行参数:getopt.getopt_long. ...

  7. Windows下解析命令行参数

    linux通常使用GNU C提供的函数getopt.getopt_long.getopt_long_only函数来解析命令行参数. 移植到Windows下 getopt.h #ifndef _GETO ...

  8. 使用 Apache Commons CLI 解析命令行参数示例

    很好的输入参数解析方法 ,转载记录下 转载在: https://www.cnblogs.com/onmyway20xx/p/7346709.html Apache Commons CLI 简介 Apa ...

  9. 3.QT中QCommandLineParser和QCommandLineOption解析命令行参数

     1  新建项目 main.cpp #include <QCoreApplication> #include <QCommandLineParser> #include & ...

随机推荐

  1. keepalived配置主从备份

    keepalived配置主从备份   keepalived是一个用于做双机热备(HA)的软件,常和haproxy联合起来做热备+负载均衡,达到高可用. 运行原理 keepalived通过选举(看服务器 ...

  2. python3 urllib

    1.获取页面内容 第一种方式: import urllib.request url = 'https://www.baidu.com/' r = urllib.request.urlopen(url) ...

  3. protobuf 协议 windows 下 java 环境搭建

    使用maven编译protobuf所需要的jar包 1. 安装配置maven (1)下载maven        http://maven.apache.org/    版本:apache-maven ...

  4. Parquet列式存储格式

    Parquet是面向分析型业务的列式存储格式,由Twitter和Cloudera合作开发,2015年5月从Apache的孵化器里毕业成为Apache顶级项目,最新的版本是1.8.0. 列式存储 列式存 ...

  5. POJ 2139 Six Degrees of Cowvin Bacon (floyd)

    Six Degrees of Cowvin Bacon Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Ja ...

  6. poj 3253 Fence Repair (贪心,优先队列)

    Description Farmer John wants to repair a small length of the fence around the pasture. He measures ...

  7. BOM及改变this指向

    bom ( borwser object model 浏览器对象模型) 定义js操作浏览器的属性和方法 window.open(url way())    中有两个参数 url代表打开的网页地址 wa ...

  8. git log --author详解,这个是个模糊匹配

    git log --author=authorname --author=<pattern>, commits whose author matches any of the given ...

  9. Fork/Join编程模型

    1.一种并行计算的多线程编程模型 2.开始--任务分割--多线程异步执行---任务合并--阻塞等待合并结果.(分治算法) 3.work-stealing算法: 每个线程维护一个各自的双端的链表,有新任 ...

  10. MySQL 删除数据库的两种方法

    使用 mysqladmin 删除数据库 使用普通用户登陆mysql服务器,你可能需要特定的权限来创建或者删除 MySQL 数据库. 所以我们这边使用root用户登录,root用户拥有最高权限,可以使用 ...