get Text From Assets - Android App

Android examples for App:Assets

Description

get Text From Assets

Demo Code


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

public class Main {

    public static String getTextFromAssets(Context context, String filename) {
        String result = null;/*from w ww  .  j  ava 2s.c  om*/

        try {
            InputStream in = context.getAssets().open(filename);
            byte[] bytes = new byte[in.available()];
            in.read(bytes);
            result = new String(bytes);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return result;
    }
}

Related Tutorials