user3438489
user3438489

Reputation: 319

acccepting file names using command line in java

I'm trying to accept 3 filenames through a command line. This is the code I tried but not working.. ?? Pls help

public class MedicalStudentMatcher {

enum Arguments {
    HospitalFile, ResidentFile, OutputFile
};

/**
 * @param args
 */
public static void main(String[] args) {

    //Retrieve file locations from command line arguments
    String hospitalFile = "";
    String residentFile = "";
    String outFile = "";


    if (args.length > 2){
        hospitalFile = args[Arguments.HospitalFile.ordinal()];
        residentFile = args[Arguments.ResidentFile.ordinal()];
        outFile = args[Arguments.OutputFile.ordinal()];
    } else {
        System.out
                .println("Please include names for the preference files and output file when running the application.\n "
                        + "Usage: \n\tjava MedicalStudentMatcher hospital.csv student.csv out.txt\n");
        return;
    }

Upvotes: 1

Views: 168

Answers (1)

sheu
sheu

Reputation: 304

Do some debugging. Print the length of you command line arguments as well as each argument

something like:

System.out.println(args.length);

for(String arg: args)
{
   System.out.println(arg);
}

This way you will see what you are passing to your program as arguments.

Upvotes: 1

Related Questions