java 读取 properties 属性文件
package com.xinlong.util;
import java.io.InputStream;
import java.util.Properties;
public final class Test {
public static String p1;
public static String p2;
static
{
Properties prop = new Properties();
InputStream in = Object.class.getResourceAsStream("/struts.properties");
try{
prop.load(in);
p1=prop.getProperty("path").trim();
p2=prop.getProperty("IndexDir").trim();
}catch(Exception ex)
{
}
}
private Test () {
}
/**
* @return the p1
*/
public static String getP1() {
return p1;
}
/**
* @param p1 the p1 to set
*/
public static void setP1(String p1) {
Test.p1 = p1;
}
/**
* @return the p2
*/
public static String getP2() {
return p2;
}
/**
* @param p2 the p2 to set
*/
public static void setP2(String p2) {
Test.p2 = p2;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("1======="+getP1());
System.out.println("2======"+getP2());
}
}