get File To List From Raw - Android App

Android examples for App:Raw

Description

get File To List From Raw

Demo Code


//package com.java2s;
import android.content.Context;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static List<String> getFileToListFromRaw(Context context,
            int resId) {
        if (context == null) {
            return null;
        }//from   w  ww.  ja v  a  2s  . c o  m

        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