手机版
你好,游客 登录 注册
背景:
阅读新闻

Java中使用配置文件——properties类

[日期:2015-02-03] 来源:Linux社区  作者:u010515761 [字体:大 中 小]

在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类中直接调用该属性获取其配置值。

本文永久更新链接地址:http://www.linuxidc.com/Linux/2015-02/112783.htm

linux
相关资讯       Java Properties 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款