icn
icn

Reputation: 17876

java program in eclipse to read text file in command line

I am trying to read a text file in eclipse, I have "run configurations" -> arguments set in eclipse , but it always says

Exception in thread "main" java.io.FileNotFoundException:  file.txt (The system cannot find the file specified)

I have put file.txt under the same folder of myclass and in /bin folder

What else I should look into?

Thanks

Upvotes: 1

Views: 5494

Answers (3)

TK Gospodinov
TK Gospodinov

Reputation: 8452

If you need to read a file from within an Eclipse plugin you are creating, you should treat at as a resource. Check this for an example: http://www.vogella.de/blog/2010/07/06/reading-resources-from-plugin/ Hope that helps.

Upvotes: 0

QuantumMechanic
QuantumMechanic

Reputation: 13946

Set the working or starting directory in the run configuration, then put the file in that directory.

Upvotes: 2

MByD
MByD

Reputation: 137392

Put it in the folder of the project, not in bin folder. If you want to see what is the base path of the files, you can print:

System.out.println(new File(".").getCanonicalPath());

Upvotes: 1

Related Questions