java读取配置文件

来源:互联网 发布:cdce.cf ad.js原理 编辑:程序博客网 时间:2024/06/08 01:25

package test01;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class ProUtil {
private Properties pro;//定义pro
private String filePath;//路径
/**
* 构造方法
*/
public ProUtil(String filepath){
this.filePath=filepath;
this.pro=read();
}

/* * 读取配置文件 */private Properties read(){    Properties properties=new Properties();//实例化    try {        InputStream inputstream=new FileInputStream(filePath);        BufferedInputStream in =new BufferedInputStream(inputstream);        properties.load(in);    } catch (IOException e) {        // TODO Auto-generated catch block        e.printStackTrace();    }    return properties;}public  String getPro(String key) {if(pro.containsKey(key)){    String username=pro.getProperty(key);//读取文件    return username;    }else{    System.out.println("你获取的key值不对");    return "";}}

}

原创粉丝点击