get String List From Raw - Android android.content.res

Android examples for android.content.res:Raw

Description

get String List 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 List<String> getStringListFromRaw(Context context,
            int resId) {
        if (context == null) {
            return null;
        }/*www.  j  a va2 s  .c  om*/

        List<String> fileContent = new ArrayList<String>();
        BufferedReader reader = null;
        try {
            InputStreamReader in = new InputStreamReader(context
                    .getResources().openRawResource(resId));
            reader = new BufferedReader(in);
            String line = null;
            while ((line = reader.readLine()) != null) {
                fileContent.add(line);
            }
            reader.close();
            return fileContent;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }

}

Related Tutorials