六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 13|回复: 0

在j2me中载入propreties资源

[复制链接]

升级  86%

49

主题

49

主题

49

主题

秀才

Rank: 2

积分
179
 楼主| 发表于 2013-2-4 19:59:56 | 显示全部楼层 |阅读模式
public Properties load(String res) throws IOException    {        Properties prop = new Properties();        DataInputStream is = null;        try        {            is = new DataInputStream(this.getClass().getResourceAsStream(res));            StringBuffer sb = new StringBuffer();            for (int i = is.read(); i > 0; i = is.read())            {                char c = (char) i;                if (c == '\r' || c == '\n')                {                    String line = sb.toString();                    if (line != null && !line.equals(""))                    {                        parseLine(prop, line);                        sb = new StringBuffer();                    }                }                else                {                    sb.append((char) i);                }            }            parseLine(prop, sb.toString());        }        finally        {            if (is != null)            {                try                {                    is.close();                }                catch (IOException e) { e.printStackTrace(); }            }        }        return prop;    }    private  void parseLine(Properties prop, String line)    {        if (line != null && !line.equals(""))        {            int pos = line.indexOf(":");            prop.addProperty(line.substring(0, pos), line.substring(pos + 2, line.length()));        }    }
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表