Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running a Java program in Eclipse as if from command line

Tags:

java

eclipse

So I've found a few questions similar to mine, but none have specifically addressed the issue I'm having.

My program will be invoked by a command line argument such as:

java Main "inputFile.txt" "inputFile2.txt"

I'm programming in Eclipse and am using the public void main(String[] args) to expect an arg[0] and arg[1]

However when I run in eclipse there is no way for me to enter which files I use. To work around this I added the 2 files I need into my project works-pace. Then in run configuration, I specified those to files as: inputFile.txt inputFile2.txt

So when I run the program now it is simply saying it cannot find inputFile.txt

Basically I'm not sure where the issue is, whether I'm entering the arguments in run configuration wrong, whether I'm placing them in my work-space incorrectly, or whether my code is incorrect.

like image 723
Gasper Gulotta Avatar asked May 10 '26 18:05

Gasper Gulotta


1 Answers

You need to go to: Run Configuration > Argument > Program argument. Then copy and paste

 "inputFile.txt" "inputFile2.txt"

inside the box.

enter image description here

like image 174
Hamid Avatar answered May 13 '26 08:05

Hamid



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!