我试图通过命令行接受3个文件名。这是我尝试但不工作的代码.. ??请帮忙
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;
}
答案 0 :(得分:1)
做一些调试。打印命令行参数的长度以及每个参数
类似的东西:
System.out.println(args.length);
for(String arg: args)
{
System.out.println(arg);
}
通过这种方式,您将看到您作为参数传递给程序的内容。