【发布时间】:2014-04-26 00:55:41
【问题描述】:
我正在尝试通过命令行接受 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;
}
【问题讨论】:
-
你得到的确切错误是什么?
-
你是在命令行中传递名字吗?
-
好吧,它进入 else 循环.. 它不接受值
-
你的意思是
else branch,无论如何,args[Arguments.HospitalFile.ordinal()]被过度设计了。如果您不能使用纯整数索引,则最好使用命令行参数解析器。看这里stackoverflow.com/questions/1524661/… -
认真考虑使用类似 commons-cli commons.apache.org/cli