0

I have two Java Projects, and I am trying to read the properties file in one from another. I have added "Infrastructure" Project in Build path of "Java" Project, and the properties file is at root folder, but I am getting java.io.FileNotFoundException I tried bunch ways, but couldn't make it work. Which part is causing the problem?

public static void main(String[] args) throws Exception {
    Properties properties = new Properties();
    properties.load(new FileInputStream("application.properties"));
}

Here is the Project Explorer;

enter image description here

Mr. Polywhirl
  • 35,562
  • 12
  • 75
  • 123
Can Mingir
  • 331
  • 2
  • 14
  • Add a `resources/` folder under `src/` and load the properties file from the ClassLoader using `getResourceAsStream()`. See: [SO: Loading files with ClassLoader](http://stackoverflow.com/questions/1119740/loading-files-with-classloader) – Mr. Polywhirl May 02 '14 at 21:32

1 Answers1

2

Use: properties.load(YourClass.class.getResourceAsStream("/application.properties")) instead.

David Xu
  • 5,409
  • 3
  • 25
  • 48