Working with Assets

Android offers one more directory where you can keep files to be included in the package: /assets. It's at the same level as /res, meaning it's not part of the /res subdirectories. The files in /assets do not generate IDs in R.java; you must specify the file path to read them. The file path is a relative path starting at /assets. You will use the AssetManager class to access these files:

//Note: Exceptions are not shown in the code

String getStringFromAssetFile(Activity activity) {

AssetManager am = activity.getAssets(); InputStream is = am.open("test.txt"); String s = convertStreamToString(is); is.close(); return s;

0 0

Post a comment