get Asset String from asset file - Android App

Android examples for App:Assets String

Description

get Asset String from asset file

Demo Code


//package com.java2s;

import java.io.InputStream;
import android.content.Context;

public class Main {
    public static String getAssetString(Context ctx, String asset) {
        InputStream is = null;//from w w  w. j a  v a  2 s. c  om
        byte[] data = null;
        try {
            is = ctx.getAssets().open(asset);
            int length = is.available();
            data = new byte[length];
            is.read(data);
        } catch (Exception ex) {
        } finally {
            try {
                is.close();
            } catch (Exception exe) {

            }
        }
        String xml = new String(data);
        return xml;
    }
}

Related Tutorials