0

Given I am able to load my mail.properties file such as :

ResourceBundle rb = ResourceBundle.getBundle("META-INF.mail");
System.out.prinltn("subject :" + rb.getString("email.subject")); //output : 'subject : Job Application'

However I am unable to read; in the same method; my mail.properties file as a FileInputStream. I have tried all these options none of them worked and I am always getting a FileNotFoundException :

FileInputStream fis = new FileInputStream("META-INF/mail.properties");
FileInputStream fis = new FileInputStream("META-INF//mail.properties");
FileInputStream fis = new FileInputStream("META-INF\\mail.properties");

The folder META-INF exists within a jar that is loaded at build time :

enter image description here

Any help will be more than appreciated.

ecdhe
  • 421
  • 4
  • 17

1 Answers1

1

The problem is FileInputStream() will look for paths relative to current directory. Since your META-INF is inside the imported jar, it won't be able to find it.

As per this post, you have following options:

  1. Specify an absolute filename
  2. Specify a relative filename which takes into account where you're running this
  3. Bundle the file as a resource and use Class.getResourceAsStream or similar

check it out for more details. My question if you are able to load it with ResourceBundle, why are you trying to reload it in a different way?

tryingToLearn
  • 10,691
  • 12
  • 80
  • 114
  • Thanks for your feed-back. To answer your question : It is related to this question : https://stackoverflow.com/questions/49366941/unable-to-read-the-last-duplicate-key-of-a-properties-file I would like to make sure I am reading the right mail.properties file. To do that I want to print the whole mail.properties file into the console or copy/paste it in some other folder. – ecdhe Mar 20 '18 at 09:50
  • Then try with the absolute file path. To get absolute path inside jar, see this answer: https://stackoverflow.com/a/14612564/2458858 – tryingToLearn Mar 20 '18 at 09:53