java读取属性配置文件工具类

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
/**
 *
 * 类: ProUtil <br>
 * 描述: 属性配置文件读取类 <br>
 * 作者: poseidon<br>
 * 版本: 1.0<br>
 * 时间: 2015-7-17 上午09:20:17
 */
public class ProUtil {
    /* 私有构造方法,防止被实例化 */
    private ProUtil (){};
    public static Properties  propertie = null;
    static {
         propertie = new Properties();
        InputStream inputStream = ProUtil.class.getResourceAsStream("/config.properties");
        try {
            propertie.load(inputStream);
            inputStream.close();
        } catch (IOException e) {
        }
    }

    public static void main(String[] args) {
        System.out.println("--->"+ProUtil.propertie.get("username"));  //username
    }
}
时间: 2024-07-30 03:02:41

java读取属性配置文件工具类的相关文章

Java读取properties文件工具类并解决控制台中文乱码

1.建立properts文件(error.message.properties) HTTP201= 请求成功并且服务器创建了新的资源 2.在spring-mvc.xml文件(applicationContext-mvc.xml)中配置properties工具类路径及读取properties文件的路径 <bean id="propertyConfigurer" class="com.yjlc.platform.utils.PropertyConfigurer"

java读取properties的工具类PropertiesUtil

1 package org.properties.util; 2 3 import java.io.FileInputStream; 4 import java.io.FileOutputStream; 5 import java.io.IOException; 6 import java.io.InputStream; 7 import java.io.OutputStream; 8 import java.util.Properties; 9 10 11 public class Prope

java读取.txt文件工具类FileUtiles

public class FileUtils { private static final String ENCODING = "UTF-8";//编码方式 /** * 获取文件的行 * * @param fileName * 文件名称 * @return List<String> */ public static String getContentByLine(String fileName) { StringBuffer lines = new StringBuffer

java读取properties配置文件总结

java读取properties配置文件总结 在日常项目开发和学习中,我们不免会经常用到.propeties配置文件,例如数据库c3p0连接池的配置等.而我们经常读取配置文件的方法有以下两种: (1).使用getResourceAsStream()方法读取配置文件. (2).使用InputStream()流去读取配置文件. 注意:在使用getResourceAsStream()读取配置文件时,要特别注意配置文件的路径的写法. this.getClass.getResourceAsStream(f

java 读取配置文件工具类 (how to read values from properties file in java)

Java 读取配置文件工具类 使用 java.util.Properties import java.io.IOException; import java.io.InputStream; import java.util.Properties; public class PropertiesReader { private static Properties prop; static { reload(); } private static void reload() { prop = new

读取Config文件工具类 PropertiesConfig.java

package com.util; import java.io.BufferedInputStream; import java.io.FileInputStream; import java.io.InputStream; import java.util.Properties; /** * 读取Config文件工具类 * @version 1.0 * @since JDK 1.6 */ public class PropertiesConfig { /** * 获取整个配置文件中的属性 *

java读取properties配置文件

java读取.properties配置文件 这两天做java项目,用到属性文件,到网上查资料,好半天也没有找到一个满意的方法能让我读取到.properties文件中属性值,很是郁闷,网上讲的获取属性值大概有以下方法,以下三种方法逐渐优化,以达到最好的效果以下都以date.properties文件为例,该文件放在src目录下,文件内容为 startdate=2011-02-07 totalweek=25 方法一: public class Stweek { static private Strin

java中常用的工具类(三)

继续分享java中常用的一些工具类.前两篇的文章中有人评论使用Apache 的lang包和IO包,或者Google的Guava库.后续的我会加上的!谢谢支持IT江湖 一.连接数据库的综合类 Java 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53

Java读取properties配置文件常用方法

在开发中对properties文件的操作还是蛮经常的,所以总结了几种操作方法,为后面的开发可以进行参考. 1.通过java.util.ResourceBundle类来读取 这边测试用到了枚举类进行传入文件的key值,然后获取value,可以进行灵活的配置. 通过这种方式读取properties文件不需要加.properties后缀名,只需文件名即可,如果有放在某一个包下,要加包的限定名,如放在com.frame.util包下,则要路径要用com/fram/util config.properti