Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

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.

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!

like image 526
Todd Avatar asked Dec 18 '09 16:12

Todd


3 Answers

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

like image 171
Robert Christie Avatar answered Oct 18 '22 21:10

Robert Christie


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.

like image 26
Jonathan Feinberg Avatar answered Oct 18 '22 21:10

Jonathan Feinberg


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.

like image 3
BryanD Avatar answered Oct 18 '22 19:10

BryanD