get String From Raw - Android android.content.res

Android examples for android.content.res:Raw

Description

get String From Raw

Demo Code

import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.text.TextUtils;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

public class Main{


    public static String getStringFromRaw(Context context, int resId) {
        if (context == null) {
            return null;
        }//from ww w.ja v  a 2s .co m

        StringBuilder s = new StringBuilder();
        try {
            InputStreamReader in = new InputStreamReader(context
                    .getResources().openRawResource(resId));
            BufferedReader br = new BufferedReader(in);
            String line;
            while ((line = br.readLine()) != null) {
                s.append(line);
            }
            return s.toString();
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }

}

Related Tutorials