java读取properties文件

来源:互联网 发布:dpp软件怎么调色 编辑:程序博客网 时间:2024/05/21 06:56

user_info.properties文件

energy_rslgsName=张家口荣庆energy_rlgsdb=HeatTubeNetWork_zhangjiakourongqing

java文件

package com.pul.sam.login;import java.io.IOException;import java.io.InputStream;import java.io.UnsupportedEncodingException;import java.util.Properties;public class test {// 构造方法private test() {}private static String rlgsName;private static String rlgsDb;public static String getRlgsName() {return rlgsName;}public static String getRlgsDb() {return rlgsDb;}// 静态方法static {Properties props = new Properties();// 读取配置文件,配置文件的相对路径以类文件所在目录作为当前目录。InputStream in = test.class.getResourceAsStream("user_info.properties");try {props.load(in);rlgsName = props.getProperty("energy_rslgsName");//String value2 = new String(rlgsName.getBytes("ISO-8859-1"),"UTF-8");rlgsDb = props.getProperty("energy_rlgsdb");} catch (IOException e) {e.printStackTrace();}}// 测试public static void main(String args[]) throws UnsupportedEncodingException {//String string = new String(getRlgsName().getBytes("ISO-8859-1"),"UTF-8");//System.out.println(string);System.out.println("热力公司名字----->" + new String(getRlgsName().getBytes("ISO-8859-1"),"UTF-8"));System.out.println("热力公司名字----->" + getRlgsDb());}}


0 0
原创粉丝点击