使用命令行文件输入从IntelliJ运行程序 [英] Run programme from IntelliJ with command line file input

查看:117
本文介绍了使用命令行文件输入从IntelliJ运行程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用IntelliJ 14.1.15运行OSX 10.11。

I am running OSX 10.11 with IntelliJ 14.1.15.

我有一个程序以txt文件作为参数。我可以通过 java SearchCmd test.txt 从终端运行它,然后它允许我输入搜索词并搜索该列表。

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.

如何从IntelliJ中执行此操作,以便我可以单击运行按钮并读取文件,我可以在IntelliJ控制台中输入搜索词。

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.

主类'SearchCmd'包含main方法,如下:

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]);
}

然而,当我尝试运行它时会说:用法:java SearchCmd 。

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

为了将test.txt文件传递给IntelliJ,我在运行/调试配置中输入了文件路径。
可悲的是我无法附上照片。 : - (

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. :-(

任何有关修复此问题并帮助我从IntelliJ运行它的帮助将不胜感激。

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

推荐答案

我只是弄明白了。

因此,您需要粘贴一个亲戚,而不是粘贴在绝对路径中从IntelliJ项目的根目录开始的路径。最重要的是你必须省略最初的正斜杠。

So instead of pasting in an absolute path, you need to paste a relative path from the root directory of your IntelliJ project. And most importantly you have to ommit the initial forward slash.

所以我的文件的绝对路径可能是这样的:
计算机/项目/ TestInput / itcwww-small.txt

So my absolute path to the file might be this: Computer/project/TestInput/itcwww-small.txt

但我需要输入程序参数的路径是:
TestInput / itcwww-small .txt

But the path that I need to put into Programme Arguments is: TestInput/itcwww-small.txt

我希望这会帮助其他人。

I hope that this will help someone else.

这篇关于使用命令行文件输入从IntelliJ运行程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆