Java can not read the file except in the root directory of the project


I am using IDEA 14 to follow a simple Java tutorial (JDBC). As part of this, I am storing some configuration properties in a file called When I put this in the root directory of the project, I can read it with the following:

Properties props = new Properties();
props.load(new FileInputStream(""));

However, as soon as I move it to any other directory in the project, I get the error "No such file or directory". This happens regardless of whether I specify a relative or absolute path:

Maybe there are more standard ways to use config files, but I would really like to understand the behavior I am observing. Thanks for helping!

By default root directory would be added to your project's build path. Since the directory in which you are putting the file is not added in your project's build path jvm is unable to find the file. You have two options:

  1. Add the folder where you are putting your prop to build path.
  2. Access the file with full path i.e. /home/user/workspace/....