Do I need to close() both FileReader and BufferedReader?

I’m reading a local file using a BufferedReader wrapped around a FileReader: BufferedReader reader = new BufferedReader(new FileReader(fileName)); // read the file // (error handling snipped) reader.close(); Do I need to close() the FileReader as well, or will the wrapper handle that? I’ve seen code where people do something like this: FileReader fReader = new … Read more

Java can’t find file when running through Eclipse

The problem is most likely that your application is using a relative pathname. As @BalusC says, relative pathnames can be problematic. But IMO, he goes way too far when he says “[y]ou should never use relative paths in java.io stuff”. When an application opens a file using (for example) the FileInputStream(File) constructor, relative pathnames are … Read more