当前位置 : 主页 > 编程语言 > c++ >

键读取系统配置文件中对应的值

来源:互联网 收集:自由互联 发布时间:2021-06-30
ConfigureFileParse.java package com.cstor.ctape.tools;import java.io.BufferedInputStream;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStream;import java.util.Properties;public class ConfigureFileParse {/*** 根
ConfigureFileParse.java
package com.cstor.ctape.tools;

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

public class ConfigureFileParse {
	
	/**
	* 根据键读取系统配置文件中对于的值
	* @param key   
	* @return String   
	* @throws
	*/
	public static String readValue(String key) {
		String filePath = Constant.ConfigureFilePath;
		Properties props = new Properties();
		InputStream in = null;
		String value = null;
        try {  
            in = new BufferedInputStream(new FileInputStream(filePath));  
            props.load(in);  
            value = props.getProperty(key);  
        } catch (Exception e) {  
        } finally {
        	try {
        		if (in != null) {
        			in.close();
        		}
			} catch (IOException e1) {
			}
        }
        return value; 
	 }  
}
网友评论