Can Mingir
Can Mingir

Reputation: 345

How to read a properties file in different Java Project?

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

Upvotes: 0

Views: 2522

Answers (1)

David Xu
David Xu

Reputation: 5597

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

Upvotes: 2

Related Questions