pickerel 发表于 2013-2-4 19:59:56

在j2me中载入propreties资源

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;    }    privatevoid 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()));      }    }
页: [1]
查看完整版本: 在j2me中载入propreties资源