Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/214.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何从Project.properties或local.properties读取属性?_Android_Properties - Fatal编程技术网

Android 如何从Project.properties或local.properties读取属性?

Android 如何从Project.properties或local.properties读取属性?,android,properties,Android,Properties,很抱歉问这样一个基本的问题,但我没能找到这些信息。我想从Android项目属性文件(project.properties或local.properties)中读取设置,但我运气不好。System.getProperty似乎没有用处,总是返回null。1在android项目的资产文件夹中创建一个名为subtype.properties的文件 2编辑密钥值的文件- key=value url=www.xyz.com ..... 现在在你的活动中调用这个- Properties prop =

很抱歉问这样一个基本的问题,但我没能找到这些信息。我想从Android项目属性文件(project.properties或local.properties)中读取设置,但我运气不好。System.getProperty似乎没有用处,总是返回null。

1在android项目的资产文件夹中创建一个名为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;
 }

改用SharedReferences.:-)