Skip to content

Instantly share code, notes, and snippets.

@David-Hackro
Created July 19, 2018 17:33
Show Gist options
  • Save David-Hackro/c5ddd433fae1abc919d3d005bf0e81d8 to your computer and use it in GitHub Desktop.
Save David-Hackro/c5ddd433fae1abc919d3d005bf0e81d8 to your computer and use it in GitHub Desktop.
import android.app.Application;
import android.content.Context;
import android.content.res.AssetManager;
import android.util.Log;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import javax.inject.Inject;
public class AssetsPropertyReader {
private Context context;
private Properties properties;
public AssetsPropertyReader(Application application) {
this.context = application.getApplicationContext();
properties = new Properties();
}
public Properties getProperties(String FileName) {
try {
/**
* getAssets() Return an AssetManager instance for your
* application's package. AssetManager Provides access to an
* application's raw asset files;
*/
AssetManager assetManager = context.getAssets();
/**
* Open an asset using ACCESS_STREAMING mode. This
*/
InputStream inputStream = assetManager.open(FileName);
/**
* Loads properties from the specified InputStream,
*/
properties.load(inputStream);
} catch (IOException e) {
// TODO Auto-generated catch block
Log.e("AssetsPropertyReader",e.toString());
}
return properties;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment