package com.Test;
import java.io.InputStream;
import java.util.Properties;
public class Stweek {
static private String startdate = null; //配置文件中的属性名
static private String totalweek = null; //配置文件中的属性名
/**
* 静态加载方法
*/
static{
loads();
}
synchronized static public void loads(){
if(startdate == null || totalweek == null)
{
InputStream is = Stweek.class.getResourceAsStream("/data.properties");
Properties dbProps = new Properties();
try {
dbProps.load(is);
startdate = dbProps.getProperty("startdate");
totalweek = dbProps.getProperty("totalweek");
}
catch (Exception e) {
System.err.println("不能读取属性文件. " +
"请确保db.properties在CLASSPATH指定的路径中");
}
}
}
//取值操作
public static String getStartdate() {
if(startdate==null)
loads();
return startdate;
}
//取值操作
public static String getTotalweek() {
if(startdate==null)
loads();
return totalweek;
}
/**
* 测试
*/
public static void main(String[] args) {
String ss = Stweek.getStartdate();
System.out.println(ss);
}
import java.io.InputStream;
import java.util.Properties;
public class Stweek {
static private String startdate = null; //配置文件中的属性名
static private String totalweek = null; //配置文件中的属性名
/**
* 静态加载方法
*/
static{
loads();
}
synchronized static public void loads(){
if(startdate == null || totalweek == null)
{
InputStream is = Stweek.class.getResourceAsStream("/data.properties");
Properties dbProps = new Properties();
try {
dbProps.load(is);
startdate = dbProps.getProperty("startdate");
totalweek = dbProps.getProperty("totalweek");
}
catch (Exception e) {
System.err.println("不能读取属性文件. " +
"请确保db.properties在CLASSPATH指定的路径中");
}
}
}
//取值操作
public static String getStartdate() {
if(startdate==null)
loads();
return startdate;
}
//取值操作
public static String getTotalweek() {
if(startdate==null)
loads();
return totalweek;
}
/**
* 测试
*/
public static void main(String[] args) {
String ss = Stweek.getStartdate();
System.out.println(ss);
}
}
注:data.properteis 文件放在项目src 目录下。