Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/396.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在getopt类中指定连字符作为选项参数_Java - Fatal编程技术网

Java 如何在getopt类中指定连字符作为选项参数

Java 如何在getopt类中指定连字符作为选项参数,java,Java,我必须给“-”作为选项参数 Getopt类 我的代码如下 Getopt g = new Getopt("cm_log_parser", args, "i:s"); //-D to enable debug log while((opt = g.getopt()) != -1) { switch (opt) { case 'f'://To set file name(if above is not specified) fileNameW

我必须给“-”作为选项参数

Getopt类

我的代码如下

Getopt g = new Getopt("cm_log_parser", args, "i:s"); //-D to enable debug log


while((opt = g.getopt()) != -1)
{
    switch (opt)
    {
        case 'f'://To set file name(if above is not specified)
            fileNameWithPath = getAndCheckOptArg(fFlag, opt, g);
            fFlag = true;
            break;

        case 's'://To set the header
            String separator = getAndCheckOptArg(hFlag, opt, g);
            hFlag = true;
            breakk;
        case '?':
            usage("Invalid option" + opt + " option");
            break;
    }
}
在参数中,我希望将其命名为-s“-”,但它显示了一些错误,例如无效选项。有什么方法可以做到这一点吗?

--
中有一个特殊的含义

用户可以强制getopt()停止扫描带有特殊参数“-”的命令行。在“-”之前出现的任何元素都将按正常方式进行扫描和排列。“-”之后的任何元素都将按原样作为非选项argv元素返回。例如,“foo-a--bar-d”将返回选项“a”,然后返回-1。optind将指向“foo”、“bar”和“-d”作为非选项argv元素。getopt()将丢弃“-”


因此,恐怕您无法完成此操作。

您可以使用
-s-
(无空格)来完成此操作。我不知道Getopt是否允许这样做