简体   繁体   中英

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

在运行配置中设置工作目录或开始目录,然后将文件放在该目录中。

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM