zoukankan      html  css  js  c++  java
  • java 解析命令行参数

    下载地址: 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');
    }


    }

    }
  • 相关阅读:
    命令执行顺序控制与管道
    js获取返回首页
    手机站点击商务通无轨迹解决方法
    js文字向上滚动代码
    文字隐藏多余的文字
    QQ弹窗代码
    百度推送代码
    js手机站跳转
    js 判断时间,满足执行框架
    js切换换class
  • 原文地址:https://www.cnblogs.com/mhc-fly/p/7070360.html
Copyright © 2011-2022 走看看