Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/373.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在java中使用命令行接受文件名_Java_Enums - Fatal编程技术网

在java中使用命令行接受文件名

在java中使用命令行接受文件名,java,enums,Java,Enums,我试图通过命令行接受3个文件名。这是我试过但不起作用的代码??请帮忙 public class MedicalStudentMatcher { enum Arguments { HospitalFile, ResidentFile, OutputFile }; /** * @param args */ public static void main(String[] args) { //Retrieve file locations from command line

我试图通过命令行接受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;
    }

做一些调试。打印命令行参数的长度以及每个参数

比如:

System.out.println(args.length);

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

通过这种方式,您将看到您作为参数传递给程序的内容。

您得到的确切错误是什么?您是否在命令行中传递名称?它将转到else循环。。它不接受值您的意思是
else分支
,无论如何,
参数[Arguments.HospitalFile.ordinal()]
已注册完毕。如果不能使用纯整数索引,最好使用命令行参数解析器。看这里认真考虑使用类似公文包CLI谢谢…尝试了,参数的长度为0。。。不知道为什么。。这就是我被困在你如何运行你的应用程序。正在从命令提示符/控制台运行它吗?@user3438489右键单击何处?您是否在Eclipse或其他IDE中?您正在使用哪个IDE?在Eclipse中,右键单击您的项目,选择“运行方式”->“运行配置”。选择“(x)=参数”选项卡并在“程序参数”下输入文件列表