Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
482 views
in Technique[技术] by (71.8m points)

java - Run Program from IntelliJ with Command Line File Input

I am running OSX 10.11 with IntelliJ 14.1.15.

I have a programme which takes a txt file as an argument. I can run it from the terminal through java SearchCmd test.txt and then it allows me to enter a search term and searches that list.

How do I do this from within IntelliJ, so that I can click the run button and it reads the file and I am able to enter a search term 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 and run this it says: "Usage: java SearchCmd ".

In order to pass the test.txt file to IntelliJ, I entered the file path in the 'Run/Debug Configurations'. Sadly I can't attach the picture. :-(

Any help on fixing this and helping me run it from IntelliJ will be greatly appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Go to Run -> Edit Configurations, Select Application, then give the main class name and program arguments. Then Run.

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...