如何指定属性文件的路径 [英] How to Specify Path for Properties file

查看:132
本文介绍了如何指定属性文件的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Config。用于将参数传递给我的方法的属性文件现在我从

I am using Config. properties file for passing parameters to my methods Now i am loading file from

属性Config = new Properties();
Config.load(新的FileInputStream(C:\\Config。properties));

因为我不喜欢我想保持硬编码我怎么能用包级别设置它。或者在申请中。

As i don't want to keep it hard coded how can i set it with package level. or within application.

在此先感谢。

推荐答案

使用ResourceBundle类。您只需指定属性文件名即可。如果路径应该在类路径中,它将从任何路径获取文件。

Make use of ResourceBundle Class. You just need to specify the properties file name. It will take the file from any path,provided the path should be in the classpath.

示例:

// abc.properties is the properties file,which is placed in the class path.You just need to 
// specify its name and the properties file gets loaded.
ResourceBundle s=ResourceBundle.getBundle("abc");
        s.getString("key");   //any key from properties file...

这篇关于如何指定属性文件的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆