适用的工具类——读取Properties文件
实用的工具类——读取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;
}
/**
* 读取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;
}