Android Utililty Methods Asset Read

List of utility methods to do Asset Read


The list of methods to do Asset Read are organized into topic(s).


StringgetFileFromAssets(Context context, String file)
get File From Assets
String contents = "";
BufferedReader reader = null;
try {
    reader = new BufferedReader(new InputStreamReader(context
    String mLine = reader.readLine();
    while (mLine != null) {
        contents += mLine;
DrawablegetImgFromAsserts(Context con, String filename)
get Img From Asserts
try {
    return new BitmapDrawable(BitmapFactory.decodeStream(con
} catch (IOException e) {
    Toast.makeText(con, e.toString(), Toast.LENGTH_LONG).show();
return null;
String[]listAssetFiles(Context context, String path)
list Asset Files
String[] list;
try {
    list = context.getAssets().list(path);
} catch (Exception e) {
    return null;
return list;
StringgetfromAssets(Context ctx, String file_name)
Read a file from assets
AssetManager assetManager = ctx.getAssets();
ByteArrayOutputStream outputStream = null;
InputStream inputStream = null;
try {
    inputStream =;
    outputStream = new ByteArrayOutputStream();
    byte buf[] = new byte[1024];
    int len;
byte[]assetAsByteArray(Resources res, String path)
Load an asset from a resource and return the content as byte array.
InputStream is = res.getAssets().open(path);
ByteArrayOutputStream buf = new ByteArrayOutputStream();
byte[] temp = new byte[1024];
int read;
while ((read = > 0) {
    buf.write(temp, 0, read);