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


当前回答

点击“编辑配置…”从工具栏顶部 在弹出窗口中,确保“环境”部分展开(通过单击下拉箭头) 应用程序的命令行参数应该进入“程序参数”字段

其他回答

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

ALT-SHIFT-F10 0 [TAB] 7次

2020年11月更新。

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

这就是它的全部。

做以下步骤:-

进入运行-编辑配置->应用程序(在面板左侧)->选择你想要运行的scala应用程序->程序参数

Maytham -ɯɐɥah λɐɯ,你可以用这段代码来模拟输入文件:

System.setIn(new FileInputStream("FILE_NAME"));

或者将文件名作为参数发送,然后将其放入FileInputStream:

System.setIn(new FileInputStream(args[0]));

在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