Create a subfolder in the main folder and name its assets. Put all your .properties files in this folder (assets).
src-> Main-> assets-> mydetails.properties
You can access it using the AssetManager class.
public class MainActivity extends ActionBarActivity { TextView textView; private PropertyReader propertyReader; private Context context; private Properties properties; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); context=this; propertyReader = new PropertyReader(context); properties = propertyReader.getMyProperties("mydetails.properties"); textView = (TextView)findViewById(R.id.text); textView.setText(properties.getProperty("Name")); Toast.makeText(context, properties.getProperty("Designation"), Toast.LENGTH_LONG).show(); }
}
public class PropertyReader { private Context context; private Properties properties; public PropertyReader(Context context){ this.context=context; properties = new Properties(); } public Properties getMyProperties(String file){ try{ AssetManager assetManager = context.getAssets(); InputStream inputStream = assetManager.open(file); properties.load(inputStream); }catch (Exception e){ System.out.print(e.getMessage()); } return properties; }
}
Prashant_M
source share