读取并解析properties文件

public class SysConfig {

    private static final Properties properties = new Properties();
    static{
       Resource rs1 = new ClassPathResource("sys-config.properties");

        try {
            properties.load(rs1.getInputStream());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static String get(String key){
        return properties.getProperty(key);
    }

    public static void main(String args[]){
        SysConfig.get("emialUrl");
    }

}
时间: 2024-08-27 20:19:12

读取并解析properties文件的相关文章

【Java编程】写入、读取、遍历Properties文件

在Java开发中通常我们会存储配置参数信息到属性文件,这样的属性文件可以是拥有键值对的属性文件,也可以是XML文件,关于XML文件的操作,请参考博文[Java编程]DOM XML Parser 解析.遍历.创建XML.在该篇博文中,我将展示如何向属性文件写入键值对,如何读取属性文件中的键值对,如何遍历属性文件. 1.向属性文件中写入键值对 特别注意: Properties类调用setProperty方法将键值对保存到内存中,此时可以通过getProperty方法读取,propertyNames(

java解析properties文件

在自动化测试过程中,经常会有一些公用的属性要配置,以便后面给脚本使用,我们可以选择xml, excel或者json格式来存贮这些数据,但其实java本身就提供了properties类来处理properties文件,虽然名字叫properties,其实打开它发现就是一个记事本的文件,所以看起来也比较直观,下面是解析properties文件的实现代码. properties文件里存贮的样子是这样的,然后给他保存为xxx.properties即可. gsBAMUserName1=automation_

Spring中配置和读取多个Properties文件

public class PropertiesFactoryBeanextends PropertiesLoaderSupportimplements FactoryBean, InitializingBean Allows for making a properties file from a classpath location available as Properties instance in a bean factory. Can be used to populate any be

Spring中配置和读取多个Properties文件--转

public class PropertiesFactoryBeanextends PropertiesLoaderSupportimplements FactoryBean, InitializingBean Allows for making a properties file from a classpath location available as Properties instance in a bean factory. Can be used to populate any be

Maven组织的web项目读取WEB-INF下properties文件

开发时经常要读取properties文件的配置信息,但是properties文件所在的位置和properties访问方式不同读取方式也不同 1.访问方式一般分:java项目和web项目. 2.文件位置:与源文件相同目录和与源目录不相同 java项目与源文件相同目录读取properties文件方法,在main函数中读取 import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOExc

jena读取和解析本体文件

使用jena开发本体应用程序时,首先需要对我们利用本体构建工具,如protege等,构建的本体文件,如owl.rdf等读取并解析得到本体模型.下面给出相应的代码,不对的地方请指正. (基于jena 2.13.0,jena 3 需要java 1.8) 方式一:使用RDFDataMgr /** * 使用RDFDataMgr读取RDF文件 * * @param fileName URI或 file:filename形式路径 * @return */ public static OntModel ope

SpringBoot学习:读取yml和properties文件的内容

一.在SpringBoot实现属性注入: 1).添加pom依赖jar包: 1 <!-- 支持 @ConfigurationProperties 注解 --> 2 <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-configuration-processor --> 3 <dependency> 4 <groupId>org.springframework

[cocos2dx utils] cocos2dx读取,解析csv文件

在我们的游戏中,经常需要将策划的数值配置成csv文件,所以解析csv文件就是一个很common的logic, 例如如下csv文件: 下面是一个基于cocos2dx 2.2.4的实现类: #ifndef __Cell__GCCsvHelper__ #define __Cell__GCCsvHelper__ #include <iostream> #include "cocos2d.h" #include <vector> USING_NS_CC; class GC

解析Properties文件

/** * 传入需要解析的文件属性,传入文件的路径 * @param para 需要获取的属性名称.也就是键值对中的键名称 * @param filepath * @return */ public static String getPara(String para,String filepath){ InputStream is = null; try{ Properties properties = new Properties(); //接下来需要获取.properties的文件路径: S