java 如何使用参数在cmd中运行java程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40490628/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 05:16:17  来源:igfitidea点击:

How to run a java program in cmd with arguments

javacmdjavac

提问by Ioanna Katsanou

This is a beginner question. I am trying to run a java program from cmd with arguments. This is my class:

这是一个初学者的问题。我正在尝试从带有参数的 cmd 运行 java 程序。这是我的课:

public class Test{
    public static void main(String[] args){
        System.out.println("This is a test");
        System.out.println(args.length);
    }
}

I can run it without arguments successfully. How can I put for example 5 and 6 as arguments in my program?

我可以在没有参数的情况下成功运行它。如何将例如 5 和 6 作为参数放入我的程序中?

All the other answers I found where just to run the program. I already know how to do that. I was not able to find how to run the program using arguments.

我找到的所有其他答案只是为了运行程序。我已经知道该怎么做了。我无法找到如何使用参数运行程序。

回答by Berserk

java Test arg1 arg2 arg3 ...

or

或者

java Test "arg1 arg2 arg3" ...

More details here Command-Line Arguments

此处的更多详细信息命令行参数