package propertyFile;
import java.util.*;
import java.io.*;
public class ReadProperties {
private InputStream configFile;
private Properties props;
public ReadProperties(){
}
public String getProperty(String property){
return props.getProperty(property);
}
public void loadConfig() throws IOException{
//当前类文件目录下的文件
configFile = getClass().getResourceAsStream("purseConfig.properties");
props = new Properties();
props.load(configFile);
}
public void loadConfig(String fileName) throws IOException{
configFile = (InputStream) new FileInputStream(new File(fileName));
props = new Properties();
props.load(configFile);
}
public void setProp(String name,String value)
{
if (props==null)
props = new Properties();
props.put(name,value);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
// try {
// ReadProperties pro = new ReadProperties();
// //pro.loadConfig("F:/workspace/Study/src/com/properties/Config.properties");
// pro.loadConfig();
// System.out.println(pro.getProperty("name"));
// System.out.println(pro.getProperty("APPKEY"));
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
ReadProperties pro = new ReadProperties();
System.out.println(pro.getPropertyByName("name"));
System.out.println(pro.getPropertyByName("APPKEY"));
}
public static String getPropertyByName(String strName){
String str = "";
try {
ReadProperties pro = new ReadProperties();
pro.loadConfig();
str = pro.getProperty(strName);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return str;
}
public static String getPropertyAPPKEY(){
String str = "";
try {
ReadProperties pro = new ReadProperties();
pro.loadConfig();
str = pro.getProperty("APPKEY");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return str;
}
purseConfig.properties
内容为:
APPKEY=n7u
分享到:
相关推荐
参考博文: http://blog.csdn.net/joe_storm/article/details/16960735
读取环境变量测试
import java.io.IOException; import java.io.InputStream; import java.util.Properties; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; public class ReadProperties ...
。特性 读取文件的全部内容。 安装 $ npm install utils-fs-read-properties 用法 var read = require ( 'utils-fs-read-properties' ) ; read(path,[options,] clbk) 读取文件的全部内容。...
19、去掉 UserControl_ReadProperties 中的判断条件,现在在窗体设计时,就可看到菜单效果!(2012-12-06) 20、解决 菜单通过 Unload 被动态删除了,绘制时的问题!(2012-12-06) 21、系统菜单的删除操作函数完成。...