I’m working on a small utility class that originally was going to read in one of four file types, which I had working. Then I found out that after I know which type of file I”m dealing with, I had to know which operation was to be performed, so the obvious choice was to use two arguments. The problem is I haven’t worked with command line args much and I’ve never had to do multiple args on the command line.
So my questions are: is there some sample code to look at or do I just hack out some procedural code that specifically looks for something at args[0] and then at ags[1]?
Also, I wanted to know how to set the args values when running it under Eclipse so I don’t pass anything in? Like when args is null because I’m not running it on the command line. So I hard code some values in the program itself under an else condition as in:
if(args.length() > 1){
}
else{
//Sets args here.
}
Thanks,
James
There are many Java libraries that offer command line handling, see SO:Java library for parsing command-line parameters. You scenario you described however seems arguably simple enough to just use
argsdirectly.Note that
argsis an array, thereforelengthis not a method:args.length > 1.. (no brackets)In order to set command line arguments in Eclipse have a look at SO:How to make Eclipse prompt me for command line arguments.