1

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;
    }
Subhrajyoti Majumder
  • 40,646
  • 13
  • 77
  • 103
user3438489
  • 309
  • 2
  • 5
  • 14

1 Answers1

1

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.

sheu
  • 284
  • 5
  • 13
  • thanks.. tried that and the length of the argument is 0... dont know why.. that's where I'm stuck at – user3438489 Mar 19 '14 at 16:34
  • how are you running you application. are running it from command prompt/ console? – sheu Mar 19 '14 at 16:38
  • @user3438489 right click where? Are you inside Eclipse or some other IDE? – ajb Mar 19 '14 at 16:44
  • Which IDE are you using? – sheu Mar 19 '14 at 16:45
  • You have to pass file names as arguments to your java main class. Test your code first with running it in command line. If your are using an IDE try to find arguments in run configurations. – Nader Ghanbari Mar 19 '14 at 16:52
  • 1
    In eclipse, right click on you project, select "Run As"-> "Run Configurations" . Select "(x)=Arguments" tab and enter the list of your files under Program arguments – sheu Mar 19 '14 at 17:02
  • Upvotes for you because I answered another of his questions and got no upvote love either. :) – crthompson Mar 21 '14 at 21:05