你把输入文件放在 eclipse(java) 的什么地方以便从控制台命令读取它?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1929415/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 01:31:55  来源:igfitidea点击:

Where do you put input file in eclipse(java) in order to read it from console command?

javaeclipseconsoleresourcesworkspace

提问by Todd

I am writing a java program in eclipse(galileo version). The program reads simple user data from input file specified at console command and process it.

我正在 eclipse(伽利略版)中编写一个 java 程序。该程序从控制台命令指定的输入文件中读取简单的用户数据并对其进行处理。

But I am not sure where I should place this input file inside eclipse workspace, so that when I run program in eclipse and type in input file name, it can be found and program can process it.

但是我不确定我应该把这个输入文件放在 eclipse 工作区的什么地方,这样当我在 eclipse 中运行程序并输入输入文件名时,它可以被找到并且程序可以处理它。

and is there way to set file path so that I can just place input file anywhere and specified the file path at runtime?

有没有办法设置文件路径,以便我可以将输入文件放在任何地方并在运行时指定文件路径?

thanks!

谢谢!

采纳答案by Robert Christie

The Java process is started with the project directory as the working directory by default.

默认情况下,Java 进程以项目目录作为工作目录启动。

回答by Jonathan Feinberg

The default working directory, when you run a Java app in Eclipse, is the project directory. If you place your data file in that directory, you can simply refer to the file without any preceding path. You can also change the working directory but modifying the launch properties for your app.

在 Eclipse 中运行 Java 应用程序时,默认工作目录是项目目录。如果您将数据文件放在该目录中,则可以直接引用该文件而无需任何前面的路径。您还可以更改工作目录,但修改应用程序的启动属性。

回答by BryanD

Alternatively you can just specify the file path as an argument to your Java process. Under the Run menu, choose Run Configurations... You should see your class under Java Applications. Select the Arguments tab and just specify the path in the Program Arguments field.

或者,您可以将文件路径指定为 Java 进程的参数。在 Run 菜单下,选择 Run Configurations... 您应该会在 Java Applications 下看到您的类。选择 Arguments 选项卡并在 Program Arguments 字段中指定路径。