Android Context Get getStringFromResource(int resource, Context context)

Here you can find the source of getStringFromResource(int resource, Context context)

Description

get String From Resource

Declaration

public static String getStringFromResource(int resource, Context context) 

Method Source Code

//package com.java2s;
import java.io.BufferedReader;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import android.content.Context;

public class Main {
    public static String getStringFromResource(int resource, Context context) {
        InputStream is = context.getResources().openRawResource(resource);
        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        String readLine = null;/*from   w  ww. j av  a  2  s .com*/
        String contents = "";

        try {
            // While the BufferedReader readLine is not null 
            while ((readLine = br.readLine()) != null) {
                contents += readLine + "\n";
            }

            // Close the InputStream and BufferedReader
            is.close();
            br.close();

        } catch (IOException e) {
            e.printStackTrace();
        }
        return contents;
    }
}

Related

  1. getSizeName(Context context)
  2. getSmiledText(Context context, CharSequence text)
  3. getSmsId(Context context)
  4. getString(Context context, String key, String defValue)
  5. getString(Context context, int resourceId)
  6. getStringResourceByName(String aString, Context context)
  7. getSystemDiskCacheDir(Context context)
  8. getTCBoldFont(Context context)
  9. getTCFont(Context context)