1

このような基本的な質問のように思えて申し訳ありませんが、この情報を見つけることができませんでした。Android プロジェクトのプロパティ ファイル (project.properties または local.properties) から設定を読み取りたいのですが、うまくいきません。System.getProperty は役に立たないようで、常に null を返します。

4

1 に答える 1

2

1 Android プロジェクトの assets フォルダーに subtype.properties という名前のファイルを作成します

2 キー値のファイルを編集します -

 key=value
 url=www.xyz.com
 .....

これをアクティビティで呼び出します-

 Properties prop = new Properties(); 
 try {
    prop = loadPropties();
 } catch (IOException e) {
    Log.e(TAG, "Exception", e);
 }

 Log.d(TAG,"The value in prop file is " + prop.getProperty("key"));



//Write this function in your activity -

private Properties loadPropties() throws IOException {
    String[] fileList = { "subtype.properties" };
    Properties prop = new Properties();
    for (int i = fileList.length - 1; i >= 0; i--) {
    String file = fileList[i];
    try {
      InputStream fileStream = getAssets().open(file);
      prop.load(fileStream);
      fileStream.close();
      }  catch (FileNotFoundException e) {
        Log.e(TAG , "Got exception " + e);
     }
  }
  return prop;
 }
于 2013-01-22T05:58:25.900 に答える