转载:
http://www.gold98.net/blog/article.asp?id=776
package test;
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;
import java.util.Properties;
import java.util.Set;
/**
* @author alex 大灰狼 from 梦想博客
*
*/
public class TestReadPropFile {
public static void main(String[] args) {
InputStream inputStream = null;
try {
String fileName = "/config.properties";
inputStream = TestReadPropFile.class.getResourceAsStream(fileName);
Properties prop = new Properties();
prop.load(inputStream);
Set keyValue = prop.keySet();
for (Iterator it = keyValue.iterator(); it.hasNext();) {
String key = (String) it.next();
String value=(String) prop.get(key);
System.out.println("key: "+key+" value: "+value);
}
System.out.println(prop.getProperty("CostExpress"));
System.out.println(prop.getProperty("path"));
inputStream.close();
} catch (IOException e) {
System.out.println(e.getStackTrace());
}
}
}
TestReadPropFile.class在非静态方法里可以用getClass()替换!
分享到:
相关推荐
今天小编就为大家分享一篇关于Java语言读取配置文件config.properties的方法讲解,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧
java如何读取properties配置文件
NULL 博文链接:https://bijian1013.iteye.com/blog/2307358
利用Java的Properties 类读取配置文件信息! 读取Properties文件的例子
主要介绍了Java 读取、获取配置文件.properties中的数据,本文通过实例代码给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下
像Python支持的配置文件是.ini文件,同样,它也有自己读取配置文件的类ConfigParse,方便程序员或用户通过该类的方法来修改.ini配置文件。在Java中,其配置文件常为.properties文件,格式为文本文件,文件的内容的...
java读取properties文件的工具类,传入配置文件名字和其中的key就可以读取
使用Java中的Properties类的方法,以及类加载器来读取配置文件中的信息。可以读取.properties文件和.cfg文件。详细代码+注释+测试例子
在我们平时写程序的时候,有些参数是经常改变的,而这种改变不是我们预知的。...而在Java 中,Java 支持的是.properties 文件的读写。JDK 内置的java.util.Properties 类为我们操作.properties 文件提供了便利。
主要介绍了java简单读取properties配置文件的方法,涉及java针对properties配置的载入及文件属性读取相关操作技巧,需要的朋友可以参考下
标准三层结构。...通过读取外部.properties配置文件获取数据库连接字符串连接数据库并进行数据库操作。 附有详细的说明,我的日食项目直接导入。 赠送3752条中英文对照句子,这些句子相信会成为很多人座右铭。
工具类里分读取.yml工具类和.properties工具类,结合博客描述使用,用不到的方法可根据个人情况删除,
读取properties文件返回map
ConfigFile configfile = ConfigFile.getInstance("ipConfig123.properties"); String ip = configfile.getkeyvalue("ip"); 可以取出ipConfig123.properties 文件中IP的内容
NULL 博文链接:https://liuzidong.iteye.com/blog/776637
NULL 博文链接:https://z-gxjs.iteye.com/blog/1846423
Java配置文件读取,采用单例模式加载config.properties
Java属性文件 如何在Java中读取config.properties值? 主跑 java crunchify / com / tutorial / CrunchifyReadConfigMain 参考
java项目读取配置文件的实例代码,使用class.getClassLoader().getResourceAsStream方法。
spring boot 配置文件