Where to put a properties file in Struts 2?

后端 未结 4 386
春和景丽
春和景丽 2020-12-16 04:58

I have a property file placed in the root of the web project in Java. I am using Struts 2. My code is unable to read properties file. Where should I keep my properties file?

4条回答
  •  没有蜡笔的小新
    2020-12-16 05:35

    Keep your myPropertyFile.properties file in src folder (after build project you will find it in WEB-INF/classes) and access them using this code:

      Properties prop = new Properties();
      ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
      prop.load(classLoader.getResourceAsStream("/myPropertyFile.properties"));
    

提交回复
热议问题