首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

适用的工具类——读取Properties文件

2012-11-03 
实用的工具类——读取Properties文件/*** 读取Properties文件*/public static Properties readProperties(St

实用的工具类——读取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;
    }

热点排行