首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

java propertis施用

2012-12-22 
java propertis使用?package com.risetek.webApp.gshfimport java.io.BufferedInputStreamimport java.i

java propertis使用

?

package com.risetek.webApp.gshf;import java.io.BufferedInputStream;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStream;import java.util.Properties;/** * <br> * description: 获取properties值,其实properties利用key和value * </br> * @author haoyf * */public class ReadProperties {private String path ="文件路径";/** * <br> * description: 通过Key获取value * </br> * @param key * properties文件中的key * @return * properties文件中的value */private String getValue(String key) {Properties property = new Properties();String value = null;InputStream in = null;try {in = new BufferedInputStream(new FileInputStream(path));property.load(in);value = property.getProperty(key);} catch (IOException e) {e.printStackTrace();} finally {try {in.close();} catch (IOException e) {e.printStackTrace();}}return value;}/** * @param args */public static void main(String[] args) {ReadProperties rp = new ReadProperties();String value = rp.getValue("key");System.out.println(value);}}

热点排行