Java tutorial
//package com.java2s; //License from project: Apache License import java.io.BufferedReader; import java.io.Closeable; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import android.content.Context; public class Main { public static String readFileFromAssets(Context context, String name) { InputStream is = null; try { is = context.getResources().getAssets().open(name); } catch (Exception e) { //Logger.e(TAG, e); } return inputStream2String(is); } public static String inputStream2String(InputStream is) { if (null == is) { return null; } StringBuilder resultSb = null; try { BufferedReader br = new BufferedReader(new InputStreamReader(is)); resultSb = new StringBuilder(); String len; while (null != (len = br.readLine())) { resultSb.append(len); } } catch (Exception ex) { //Logger.e(TAG, ex); } finally { closeIO(is); } return null == resultSb ? null : resultSb.toString(); } public static void closeIO(Closeable... closeables) { if (null == closeables || closeables.length <= 0) { return; } for (Closeable cb : closeables) { try { if (null == cb) { continue; } cb.close(); } catch (IOException e) { // Logger.e(TAG, "close IO ERROR...", e); } } } }