Guest User

Untitled

a guest
Jul 19th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. import android.app.Application;
  2. import android.content.Context;
  3. import android.content.res.AssetManager;
  4. import android.util.Log;
  5.  
  6. import java.io.IOException;
  7. import java.io.InputStream;
  8. import java.util.Properties;
  9.  
  10. import javax.inject.Inject;
  11.  
  12. public class AssetsPropertyReader {
  13. private Context context;
  14. private Properties properties;
  15.  
  16. public AssetsPropertyReader(Application application) {
  17. this.context = application.getApplicationContext();
  18. properties = new Properties();
  19. }
  20.  
  21. public Properties getProperties(String FileName) {
  22.  
  23. try {
  24. /**
  25. * getAssets() Return an AssetManager instance for your
  26. * application's package. AssetManager Provides access to an
  27. * application's raw asset files;
  28. */
  29. AssetManager assetManager = context.getAssets();
  30. /**
  31. * Open an asset using ACCESS_STREAMING mode. This
  32. */
  33. InputStream inputStream = assetManager.open(FileName);
  34. /**
  35. * Loads properties from the specified InputStream,
  36. */
  37. properties.load(inputStream);
  38.  
  39. } catch (IOException e) {
  40. // TODO Auto-generated catch block
  41. Log.e("AssetsPropertyReader",e.toString());
  42. }
  43. return properties;
  44.  
  45. }
  46.  
  47. }
Add Comment
Please, Sign In to add comment