get Text From Assets - Android android.content

Android examples for android.content:Asset

Description

get Text From Assets

Demo Code

import java.io.InputStream;

import android.content.Context;

public class Main {

  public static String getTextFromAssets(final Context context, String fileName) {
    String result = "";
    try {//from  w  w  w . j  a  v  a2  s . c  om
      InputStream in = context.getResources().getAssets().open(fileName);

      int lenght = in.available();

      byte[] buffer = new byte[lenght];

      in.read(buffer);
      result = new String(buffer, "UTF-8");
      in.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
    return result;
  }

}

Related Tutorials