I’m programming Java in Eclipse IDE. Here is code I want to read file:
File file = new File("file.txt");
reader = new BufferedReader(new FileReader(file));
I put file.txt in two place:
1) same folder of this SOURCE file.
2) in bin\...\ (same folder of this CLASS file)
But I allways receive NO FILE FOUND.
Please help me.
thanks 🙂
If the file ships with your application, it would be better accessed as a resource than as a file. Simply copy it to somewhere in your build path and use
Class.getResourceAsStreamorClassLoader.getResourceAsStream. That way you’ll also be able to access it if you bundle your app as a jar file.Currently, you’re looking for the file relative to the process’s current working directory, which could be entirely unrelated to where the class files are.