Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/318.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.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 将JCommander解析的参数保存到文件_Java_Jcommander - Fatal编程技术网

Java 将JCommander解析的参数保存到文件

Java 将JCommander解析的参数保存到文件,java,jcommander,Java,Jcommander,在中是否可以将带有jcommander.Parameter注释的类保存到文件中,这样就可以创建新的对象,并使用从文件中读取 例如,如果我对类进行了注释 class IndexerCommandLineParameters { @Parameter(names = { "-s", "--source" }, description = "Source file or directory of audio files (*.wav or *.mp3). MUST BE 16bit!", re

在中是否可以将带有
jcommander.Parameter
注释的类保存到文件中,这样就可以创建新的对象,并使用从文件中读取

例如,如果我对类进行了注释

class IndexerCommandLineParameters {
    @Parameter(names = { "-s", "--source" }, description = "Source file or directory of audio files (*.wav or *.mp3). MUST BE 16bit!", required=true)
    public String source;

    @Parameter(names = { "-d", "--destination" }, description = "Destination file or directory (type must match source type).", required=true)
    public String destination;

    @Parameter(names = { "-v", "--verbositiy" }, description = "Verbosity in stderr: 0 - print only file processing errors, 1 - print indexing progress")
    public int verbositiy=1;

    @Parameter(names = {"-f", "--force"}, description = "Force to reindex alredy indexed fiels")
    public boolean reindex = true;

    @Parameter(names = {"-h", "--help"}, description = "Force to reindex alredy indexed fiels", help = true)
    private boolean help;
}
和类初始化

IndexerCommandLineParameters p = new IndexerCommandLineParameters();
JCommander c=new JCommander(p);
c.parse("-s", "xxxxx","-d", "yyyyy");
p.verbositiy=2;
我想创建一个包含以下内容的文件

-s xxxxx -d yyyyy -v 3 -f
我知道我可以在每个类中创建
.toString()
或类似的东西,但我正在寻找更通用的东西,不必为每个带注释的类添加一些代码