在Eclipse中使用命令行

时间:2014-07-26 21:08:07

标签: java eclipse input command-line

我正在尝试使用eclipse编译并运行该程序。我该怎么做呢? 我不能在程序中包含命令行。我如何使用eclipse通过使用此命令行运行程序? 我知道使用扫描仪制作程序的另一种方法,但我如何正确运行这个? 无法张贴图片。刚加入。

从文件输入

Display a text file.
/*To use this program, specify the name
of the file that you want to see.
For example, to see a file called TEST.TXT,
use the following command line.
java ShowFile TEST.TXT */

import java.io.*;
class ShowFile {
public static void main(String args[])
throws IOException
{
int i;
FileInputStream fin;
try {
fin = new FileInputStream(args[0]);
} catch(FileNotFoundException exc) {
System.out.println("File Not Found");
return;
} catch(ArrayIndexOutOfBoundsException exc) {
System.out.println("Usage: ShowFile File");
return;
}
// read bytes until EOF is encountered
do {
i = fin.read();
if(i != -1) System.out.print((char) i);
} while(i != -1);
fin.close();
}
}

3 个答案:

答案 0 :(得分:0)

右键点击您的计划,将鼠标悬停至运行方式,然后点击运行配置 您将看到一个对话框,现在单击Arguments选项卡并指定命令行参数。 Eclipse Command Line Args

答案 1 :(得分:0)

我不确定您的要求,但要在控制台中查看您的程序输出:

你可以这样做: Window > Show View > Console

如果您想要从命令行进行编译,可以使用javac

答案 2 :(得分:0)

右键单击您的程序,将鼠标悬停在运行方式并单击运行配置您将看到一个对话框,现在单击参数选项卡并指定命令行参数。

在程序参数上只需写文件名或文件地址 无需编写 java ShowFile 在您的情况下它将是 TEST.TXT

注意:确保 TEST.TXT 文件在您的项目文件夹中