get Asset Data as byte array by asset path - Android App

Android examples for App:Assets

Description

get Asset Data as byte array by asset path

Demo Code


//package com.java2s;
import java.io.IOException;
import java.io.InputStream;
import android.content.Context;
import android.content.res.AssetManager;

public class Main {
    public static byte[] getAssetData(Context ctx, String asset) {
        AssetManager am = ctx.getAssets();
        try {//from ww w . j  av  a2  s.c o m
            InputStream is = am.open(asset);
            int length = is.available();
            byte[] data = new byte[length];
            is.read(data);
            return data;
        } catch (IOException e1) {
            e1.printStackTrace();
        }

        return null;
    }
}

Related Tutorials