0

I have a project in which I have several embedded files.files

However, when I try to access these files in the code:

Statics.applicationProperties = loadPropertyFile("application.properties");


public Properties loadPropertyFile(final String filename) {
    
    Properties props = new Properties();
    try {
        props.load(new FileReader(filename));  //<-- file not found exception here
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    
    return props;
}

I get the following error:

[08:44:06] [Server thread/WARN]: java.io.FileNotFoundException: application.properties (The system cannot find the file specified)
[08:44:06] [Server thread/WARN]:        at java.base/java.io.FileInputStream.open0(Native Method)
[08:44:06] [Server thread/WARN]:        at java.base/java.io.FileInputStream.open(FileInputStream.java:213)
[08:44:06] [Server thread/WARN]:        at java.base/java.io.FileInputStream.<init>(FileInputStream.java:155)
[08:44:06] [Server thread/WARN]:        at java.base/java.io.FileInputStream.<init>(FileInputStream.java:110)
[08:44:06] [Server thread/WARN]:        at java.base/java.io.FileReader.<init>(FileReader.java:60)
[08:44:06] [Server thread/WARN]:        at net.mcnations.nationsatwar.utils.InitializrUtils.loadPropertyFile(InitializrUtils.java:168)

I am packaging this jar file via Maven's build goals compile package.

Are these resources just not being included? I don't get it, as they are very clearly within the resources section of the project.

Matthew
  • 817
  • 1
  • 13
  • 39
  • Does this help? https://stackoverflow.com/questions/15749192/how-do-i-load-a-file-from-resource-folder – Daniel Jun 13 '21 at 13:53
  • Does this answer your question? [How do I load a file from resource folder?](https://stackoverflow.com/questions/15749192/how-do-i-load-a-file-from-resource-folder) – sanjeevRm Jun 13 '21 at 14:01

0 Answers0