Command line arguments are aggregated into an String[] in Java and passed into your main un-processed.
public static void main(final String[] args) { // code }
With your example input of D:/input a.conf,b.conf,c.conf D:/output the value of args becomes ["D:/input", "a.conf,b.conf,c.conf", "D:/output"] where the [] delimit an array of String.
You have two options:
- manually parse this
argsarray and pull it apart manually and process each element yourself. In this case you need toArrays.asList(args[2].split(","));the second argument to get it into aList<String>as you desire. - Use something like JSAP ( Java Simple Argument Parser ) and let a well tested and mature library parse, validate and format the input for you. Specifically it can parse the second argument you are passing in for you.
Needless to say, I prefer the second option because the first is just brittle busy work.
Answer from user177800 on Stack OverflowList<String> as command line argument in java - Stack Overflow
Minecraft Forge: JVM flags for high performance. (Working on low spec and high spec pc´s)
Issues passing command line arguments in launch.json
the file isn't found
IDK how the Java extension in particular deals with this but this sounds like working directory / relative path type whatnot. The program may be looking for the file in a different folder than it actually is. See here for more info - adding ${workspaceFolder} into the mix and/or "cwd" should do the job.
No clue about the "argument not received" stuff though.
More on reddit.comIs there any good library to handle command-line arguments?
How to run a Java class using the command line?
What are jar files in Java?
Command line arguments are aggregated into an String[] in Java and passed into your main un-processed.
public static void main(final String[] args) { // code }
With your example input of D:/input a.conf,b.conf,c.conf D:/output the value of args becomes ["D:/input", "a.conf,b.conf,c.conf", "D:/output"] where the [] delimit an array of String.
You have two options:
- manually parse this
argsarray and pull it apart manually and process each element yourself. In this case you need toArrays.asList(args[2].split(","));the second argument to get it into aList<String>as you desire. - Use something like JSAP ( Java Simple Argument Parser ) and let a well tested and mature library parse, validate and format the input for you. Specifically it can parse the second argument you are passing in for you.
Needless to say, I prefer the second option because the first is just brittle busy work.
public static void main(String[] args) {
int argc = 0;
if(args.length>2){
String inputFileLocation = args[0];
String configFileList = args[1];
String outputFileLocation = args[2];
List<String> lList=Arrays.asList(configFileList.split(","));
System.out.println(inputFileLocation);
System.out.println(lList);
System.out.println(outputFileLocation);
}
}
Output:
D:/input
[a.conf, b.conf, c.conf]
D:/output