get Assets Text - Android App

Android examples for App:Assets

Description

get Assets Text

Demo Code


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

public class Main {

    public static String getAssetsText(Context context, String fileName)
            throws IOException {

        AssetManager assetManager = context.getAssets();

        InputStream in = assetManager.open(fileName);
        return readStream(in);
    }//from   w w  w.j  a v  a 2  s  .c  o  m

    public static String readStream(InputStream in) throws IOException {

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        int i;
        while ((i = in.read()) != -1) {
            baos.write(i);
        }
        return baos.toString();
    }
}

Related Tutorials