例:读取shiro.propertites中的bashPath对应的值
public class ConfigUtil
{
private static String basePath;
public static String getBasePath()
{
return basePath;
}
public static void setBasePath(String basePath)
{
ConfigUtil.basePath = basePath;
}
static
{
Properties prop = new Properties();
InputStream in = Object.class.getResourceAsStream("/shiro.properties");
try
{
prop.load(in);
basePath = prop.getProperty("basePath").trim();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class BasePathUtil
{
private static String p_basePath = null;
public static String loadBasePath()
{
if (p_basePath == null)
{
p_basePath = getBasePath();
}
return p_basePath;
}
private static String getBasePath()
{
InputStream inputStream = ConfigUtil.class.getResourceAsStream("/shiro.properties");
Properties p = new Properties();
try
{
p.load(inputStream);
inputStream.close();
}
catch (IOException e1)
{
e1.printStackTrace();
}
String basePath = p.getProperty("basePath");
return basePath;
}
}
final String basePath = BasePathUtil.loadBasePath();读取数据