I usually input command line arguments in Eclipse via run configuration. But I don't know how do achieve the same task in IntelliJ IDEA.
This question is related to
command-line
arguments
intellij-idea
In IntelliJ, if you want to pass args parameters to the main method.
go to-> edit configurations
program arguments: 5 10 25
you need to pass the arguments through space separated and click apply and save.
now run the program if you print
System.out.println(args[0]);
System.out.println(args[1]);
System.out.println(args[2]);
Out put is 5 10 25
Do this steps :-
Go to Run - Edit Configuration -> Application (on the left of the panel ) -> select the scala application that u want to run -> program argument
To do this in IntelliJ IDEA 2020.2.3 (Community edition) on Windows 10:
Updated for 11/2020.
We cannot go into Terminal and give in the good old java Classname arg1 arg2 arg3
We'll have to edit the run configuration.
Step 1 : Take the Run menu
Step 2 : Select Edit Configurations
Step 3 : Fill the Program arguments field
After that, the arguments will be inserted to the end of the command that IntelliJ creates whenever you run the program :)
You separate multiple program arguments with spaces. (this was not obvious to me)
Program arguments:Julia 52 Actress
If you are using intellij go to Run > Edit Configurations
menu setting. A dialog box will appear. Now you can add arguments to the Program arguments
input field.
There's an "edit configurations" item on the Run menu, and on the pull-down to the left of the two green "run" and "debug" arrows on the toolbar. In that panel, you create a configuration with the "+" button in the top left, and then you can choose the Class containing main(), add VM parameters and command-line args, specify the working directory and any environment variables.
There are other options there as well: code coverage, logging, build, JRE, etc.
On a MacBook Air with "OSX 10.11.3":
ALT+SHIFT+F10, Right, E, Enter, Tab, enter your command line parameters, Enter. ;-)
CTRL+ALT+R, Right, E, Enter, Tab, enter your command line parameters, Enter.
Example I have a class Test:
Then. Go to config to run class Test:
Step 1: Add Application
Step 2:
You can input arguments in the Program Arguments textbox.
Main Program -> Run -> Edit Configurations -> Inside Configuration there is Program arguments text box. add space separated argument in the text box. Then you can read those arguments in the args array (public static void main(String[] args))
As @EastOcean said, We can add it by choosing Run/Debug configurations option. In my case, I have to set configuration for junit. So on clicking Edit configurations option, a pop up window is displayed. Then followed the below steps:
Save and run.
Thank you.
maytham-???i???, you can use this code to simulate input of file:
System.setIn(new FileInputStream("FILE_NAME"));
Or send file name as parameter and then put it into FileInputStream:
System.setIn(new FileInputStream(args[0]));
Source: Stackoverflow.com