2008-01-14

在j2me中载入propreties资源

关键字: j2me
    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()));
        }
    }
评论
发表评论

您还没有登录,请登录后发表评论

pickerel
搜索本博客
最近加入圈子
存档
最新评论