读书人

适用的工具类读取Properties文件

发布时间: 2012-11-03 10:57:43 作者: rapoo

实用的工具类——读取Properties文件
/**
* 读取Properties文件
*/
public static Properties readProperties(String file)
{
InputStream in = null;
Properties prop = null;
try
{
in = new BufferedInputStream(new FileInputStream(file));
prop = new Properties();
prop.load(in);
}
catch (FileNotFoundException e1)
{
throw new RuntimeException(file + " is not exist!");
}
catch (IOException e)
{
throw new RuntimeException("Read file " + file + " error!");
}
finally
{
try
{
if (null != in)
{
in.close();
}
}
catch (IOException e)
{
in = null;
throw new RuntimeException("Close IO error!");
}
}
return prop;
}

读书人网 >编程

热点推荐