zoukankan      html  css  js  c++  java
  • java 读取property

    Properties prop = new Properties();
    String path = AlarmController.class.getResource("/").getPath();  //AlarmController在哪个类里面写的就写哪个类
    System.out.println(path);              ///D:/workspace/cxfvp/src/main/webapp/WEB-INF/classes/  property放在这里
    String websiteURL = (path+ "area.properties");            //得到自己的文件位置
    try{
    //读取属性文件area.properties
    InputStream in = new BufferedInputStream (new FileInputStream(websiteURL));
    prop.load(in); ///加载属性列表
    String jinhua = prop.getProperty("jinhua");  //取value
    String hangzhou = prop.getProperty("hangzhou");
    String ningbo = prop.getProperty("ningbo");
    System.out.println(jinhua);
    }
    catch(Exception e){
    System.out.println(e);
    }

    配置文件

  • 相关阅读:
    输出流
    异常处理
    异常限制
    多个受控异常
    跟踪异常传播
    动手动脑练习2
    动手动脑练习
    文件总结
    程序员修炼之道3
    Shell教程 之printf命令
  • 原文地址:https://www.cnblogs.com/wudage/p/7592576.html
Copyright © 2011-2022 走看看