How a JAR file can read an external properties file

后端 未结 7 1054
星月不相逢
星月不相逢 2020-12-24 10:01

We have a connection pooling component (JAR file) for one of our application. As of now the application connection details are bundled with-in the JAR file (in .proper

相关标签:
7条回答
  • 2020-12-24 10:27

    Just load the properties from file, something like

    Properties properties = new Properties();
    InputStreamReader in = null;
    try {
         in = new InputStreamReader(new FileInputStream("propertiesfilepathandname"), "UTF-8");
         properties.load(in);
    } finally {
         if (null != in) {
             try {
                 in.close();
             } catch (IOException ex) {}
         }
    }
    

    Note how the encoding is explicitly specified as UTF-8 above. It could also be left out if you accept the default ISO8859-1 encoding, but beware with any special characters then.

    0 讨论(0)
提交回复
热议问题