args
represents each argument in string array from command line, so as others mentioned in case java Main blaBla.txt test.csv
you got following in the program:
args[0] blaBla.txt
(first argument)
args[1]=test.csv
(second argument)
So you can make easy check, for explanation:
if (args.length == 0 || args.length > 2) {
System.out.println("please provide one or two files");
} else if (args.length == 1) {
// got only 1 file
// file1 = args[0]
} else {
// args.length == 2 got 2 files
// file1 = args[0]
// file2 = args[1]
}
Which can be optimized like following:
if (args.length == 1) {
//got one file
} else if (args.length == 2) {
//got two files
} else {
//invalid arguments
}
to avoid redundant assign file1 in case of arguments are correct can do eg. this
if (args.length > 2 || args.length == 0) {
//none or more arguments then supported, some fail
System.out.println("Use One or Two Files!");
System.exit(1);
}
if (args.length == 1) {
//got one file or two files
//assign first
}
if (args.length == 2) {
//got two files
//also got second
}