Run the program from IntelliJ by entering the command line file

I am running OSX 10.11 with IntelliJ 14.1.15.

I have a program that takes a txt file as an argument. I can run it from the terminal via java SearchCmd test.txt , and then it allows me to enter a search query and search for this list.

How to do this from IntelliJ so that I can press the start button and it reads the file and I can enter a search query in the IntelliJ console.

The main class "SearchCmd" contains the main method, as such:

public class SearchCmd {

public static void main (String[] args) throws IOException {
    String name;

    // Check that a filename has been given as argument
    if (args.length != 1) {
        System.out.println ("Usage: java SearchCmd <datafile>");
        System.exit (1);
    }

    // Read the file and create the linked list
    HTMLlist l = Searcher.readHtmlList (args[0]);
}

However, when I try to run this, it says: "Usage: java SearchCmd".

To transfer the test.txt file to IntelliJ, I entered the file path in "Run / Debug Configurations". Sorry, I can’t attach the photo.: - (

IntelliJ .

+4
6

.

IntelliJ. , .

, : //TestInput/itcwww-small.txt

, , : TestInput/itcwww-small.txt

, - .

+1

RunEdit Configurations, Application, main class program arguments. Run.

enter image description here

+10

, -
1. Run- > Edit Configurations.
enter image description here < >
2. .

enter image description here

3. . 4.

+1

Run → Edit configuration.

" " - , . :

java MyMainClass ProgramArgument1 ProgramArgument2 ProgramArgument3

java SearchCmd test.txt

test.txt

. , - ,

0

, , , , .

.

> ....

change configuration

, , .

enter image description here

0

" " "" "":

, , , :

    try {
        FileInputStream inputStream = new FileInputStream(new File(args[0]));
        System.setIn(inputStream);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
0
source

Source: https://habr.com/ru/post/1610289/


All Articles