Windows server 2008 R2 IIS管理器
2015-06-28 20:18
351 查看
properties文件是一种配置文件,主要用于表达配置信息,文件类型为*.properties,是一种以key-value形式存储信息的文件。因为配置文件需要在整个系统中保持一致性,所以经常和单例模式配合使用。
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.Properties;
public final class Test {
private static final Properties apProp__;
// 单例模式
private Test(){}
// 静态初始化块
static{
String propertiesPath = "c://test.properties";
apProp__ = new Properties();
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader(propertiesPath));
apProp__.load(br);
} catch (Exception e) {
e.printStackTrace(System.err);
} finally {
if (br != null) {
try {
br.close();
} catch (Exception ex) { }
}
}
}
public String getProperty(String key){
return apProp__.getProperty(key);
}
}
test.properties文件内容:
path = c://test.txt
这样其他类如果想用c://test.txt这个路径的话,可以调用Test.getProperty("path")就可以了
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.Properties;
public final class Test {
private static final Properties apProp__;
// 单例模式
private Test(){}
// 静态初始化块
static{
String propertiesPath = "c://test.properties";
apProp__ = new Properties();
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader(propertiesPath));
apProp__.load(br);
} catch (Exception e) {
e.printStackTrace(System.err);
} finally {
if (br != null) {
try {
br.close();
} catch (Exception ex) { }
}
}
}
public String getProperty(String key){
return apProp__.getProperty(key);
}
}
test.properties文件内容:
path = c://test.txt
这样其他类如果想用c://test.txt这个路径的话,可以调用Test.getProperty("path")就可以了
相关文章推荐
- __LINE__ __FILE__的用法
- windows下ACtiveMQ服务器搭建
- 爬腾讯视频所有类型的电影
- Constraints on a Wildcard : Generic Parameters
- Linux-ubuntu-MyEclipse8.5 安装
- Unique Paths II
- JAVA基础第七天
- Excel 统计在某个区间内数值的个数
- FTP服务器的搭建
- IOS 开发,调用打电话,发短信,打开网址
- 认识自己——恐惧的奴隶6:老师
- 苹果API常用英文名词
- 利用div实现遮罩层效果
- emacs第一次接触
- 雷军武大演讲:快40岁时 我曾觉得梦想渐行渐远
- UVA_11039 Building Designing
- Add and Search Word - Data structure design
- 6.27博客
- JAVA基础第六天
- SpringMvc+Jdbc泛型反射BaseDao