argumen开发者_如何学编程tsset in eclipse , but it always says" />
开发者

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" -> argumen开发者_如何学编程ts 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


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


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());


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜