读取properties配置文件

来源:互联网 发布:网络机柜接线图视频 编辑:程序博客网 时间:2024/06/05 15:50
public class PropertiesUtil {    public static void main(String[] args) {        Properties p=new Properties();  //创建Properties对象          try {              InputStream in=PropertiesUtil.class.getResourceAsStream("status_code.properties");            //放置到p中,即放properties文件中的key,value            p.load(in);//读取.preperties中的信息              /*                       * p.load(new FileInputStream("db.properties")); 我们不能这样直接放如果这样放就会              * 出现一个错误java.io.FileNotFoundException: db.properties (系统找不到指定的文件。)              */              p.list(System.out);//System.out 是打印到控制台              System.out.println("****************************************");              System.out.println(p.getProperty("100"));//p.getProperty(Key) 根据Key查询Value              System.out.println(p.getProperty("200"));          } catch (Exception e) {              // TODO Auto-generated catch block              e.printStackTrace();          }      }}

java读取.properties配置文件的几种方法
这篇博客总结了几种读取方法。

Java 读写Properties配置文件
这篇博客总结了Properties这个类常用的几个方法

原创粉丝点击