在 jDeveloper IDE 中放置属性文件的位置以及如何在 Java class 中访问它

Where to put properties file in jDeveloper IDE and how to access it in Java class

我一直在使用 jDeveloper IDE 构建 JDEVADF_12.1.3.0.0_GENERIC_140521.1008.S。我的项目由基于 SOAP 的 Web 服务组成。一切看起来都不错。我的项目 运行 很好。但是,客户对属性文件有要求。

我尝试在不同的地方创建文件夹,甚至将 .properties 文件直接放在包中,并尝试使用下面的代码从中获取值。

        /* First try of fetching from properties file*/

        InputStream is = CountryRepositoryDao.class.getClassLoader().getResourceAsStream("bundle.properties");
        InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("bundle.properties");
        Properties prop = new Properties();
        prop.load(is);
        System.out.println(prop.getProperty("surname"));

        /* Second try of fetching properties file */
        ClassLoader loader = ClassLoader.getSystemClassLoader ();
        InputStream oInputStream = loader.getResourceAsStream ("config.properties");
        Properties m_Properties = new Properties();
        m_Properties.load(oInputStream);
       System.out.println(m_Properties.getProperty("surname"));

但是我得到空指针异常!我尝试了盒子里的所有技巧,但没有运气。

你们能帮帮我吗

谢谢, 神山

我已经解决了这个问题。我关注了

InputStream  adf = 
CountryRepositoryDao.class.getClassLoader().
getResourceAsStream("com/ge/fcm/dao/app.properties");

Properties prop = new Properties();
prop.load(adf);
System.out.println(prop.getProperty("surname")); //I am getting the value.

getResourceAsStream 参数中的路径有问题。

谢谢, 神山