Android Utililty Methods Asset Read

List of utility methods to do Asset Read

Description

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

Method

StringgetFileFromAssets(Context context, String file)
get File From Assets
String contents = "";
BufferedReader reader = null;
try {
    reader = new BufferedReader(new InputStreamReader(context
            .getAssets().open(file)));
    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
            .getAssets().open(filename)));
} catch (IOException e) {
    Toast.makeText(con, e.toString(), Toast.LENGTH_LONG).show();
    e.printStackTrace();
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 = assetManager.open(file_name);
    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 = is.read(temp)) > 0) {
    buf.write(temp, 0, read);
is.close();
...