设为首页 加入收藏

TOP

Java中使用配置文件——properties类
2015-02-03 22:27:35 来源: 作者: 【 】 浏览:23
Tags:Java 使用 配置 文件 properties

在java.util 包下面有一个类 Properties,该类主要用于读取项目中的配置文件(以.properties结尾的文件和xml文件)。


使用示例:


Java类:


import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;


? InputStream inputStream = Agent.class.getClassLoader().getResourceAsStream("config.properties");
? Properties properties = new Properties();
? properties.load(inputStream);
? String time = properties.getProperty("period");


配置文件config.properties:


#timer
period=30


该示例表示在config.properties中配置属性period的值为30,在java类中直接调用该属性获取其配置值。


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Python FTP 下载文件 简单示例 下一篇OpenCV在Hisi上的移植总结

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: