我通常通过运行配置在Eclipse中输入命令行参数。但是我不知道如何在IntelliJ IDEA中实现同样的任务。


当前回答

自IntelliJ IDEA 2021年以来,我对这个问题添加了更新的答案。

Select Edit Configuration from the toolbar (or under the Run menu): Picture of new location of edit configuration box You now have to click on the Modify Options menu (Alt + M) to the left of where it says Build and Run, and above the drop down menu that lets you select the version of Java (or other language) that your using. After you click Modify Options the first box you will see--titled Operating System--will have a line that says "Redirect input". Click on that to add the box for input redirection. Close Modify Options. Under Build and Run, the third box down is for command line input.

Intelij IDE的图片与编辑配置框打开箭头指向cmd行输入和输入重定向

这就是它的全部。

其他回答

我们不能进入终端,并给出良好的旧java类名arg1 arg2 arg3

我们必须编辑运行配置。

步骤1:选择Run菜单 步骤2:选择“编辑配置” 步骤3:填充程序参数字段

在此之后,参数将被插入到IntelliJ在运行程序时创建的命令的末尾:

在“运行”菜单上有一个“编辑配置”项,在工具栏上两个绿色“运行”和“调试”箭头左边的下拉菜单上。在该面板中,使用左上角的“+”按钮创建配置,然后可以选择包含main()的Class,添加VM参数和命令行参数,指定工作目录和任何环境变量。

还有其他选项:代码覆盖率、日志记录、构建、JRE等。

要在Windows 10上的IntelliJ IDEA 2020.2.3(社区版)中执行此操作:

ALT-SHIFT-F10 0 [TAB] 7次

2020年11月更新。

我使用的是IDEA 2021.3.2,我遇到了一个简单的解决方案: 只需右击你的代码区:

然后选择“修改运行配置”:

在这里输入命令行参数。

在IntelliJ中,如果您想将args参数传递给main方法。

执行->编辑配置

程序参数:5 10 25

您需要通过分隔的空格传递参数,然后单击apply并保存。

现在如果要打印,就运行程序

System.out.println (args [0]); System.out.println (args [1]); System.out.println (args [2]); 输出是5 10 25