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


当前回答

用空格分隔多个程序参数。(这对我来说并不明显)

节目论证:茱莉亚52女演员

其他回答

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

我们必须编辑运行配置。

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

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

我有一个类Test:

然后。转到配置运行类Test:

步骤1:添加应用

步骤2:

您可以在“程序参数”文本框中输入参数。

在运行“OSX 10.11.3”的MacBook Air上:

CTRL + Alt + r e 输入 程序参数: 编写命令行参数(如果有多个参数,则每个项之间有空格) 输入

自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行输入和输入重定向

这就是它的全部。

主程序->运行->编辑配置->在“配置”中有“程序参数”文本框。在文本框中添加空格分隔的参数。然后你可以在args数组中读取这些参数(public static void main(String[] args))