1

I'm working on a web application, and I have created a properties file in package com.xx.yy. I need to read this file from a class in author package com.aa.bb.

I have the folowing code:

try {
    FileInputStream fileInputStream = new FileInputStream("com/xx/yy/myfile.properties");
    internationalizationFile = new Properties();
    internationalizationFile.load(fileInputStream);
    fileInputStream.close();
} catch (Exception e) {
    e.printStackTrace();
}

but it doesn't work!!

tshepang
  • 12,111
  • 21
  • 91
  • 136
Omar IJMOUAN
  • 23
  • 1
  • 5

2 Answers2

2

Have you tried to load the resource through the class loader? like:

    InputStream in = this.getClass().getClassLoader.getResourceAsStream("com/xx/yy/myfile.properties");
hovanessyan
  • 30,580
  • 6
  • 55
  • 83
2

1) I would print out the absolute path to make sure the file / resource is in the correct location.

getResourceAsStream() vs FileInputStream

2) I would use getResourceAsStream, same reference.

Community
  • 1
  • 1