read Text File From Raw Resource Id - Android android.content

Android examples for android.content:Context

Description

read Text File From Raw Resource Id

Demo Code

import android.content.Context;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Main{

    public static String readTextFileFromRawResourceId(Context context,
            int resourceId) {
        StringBuilder builder = new StringBuilder();

        BufferedReader reader = new BufferedReader(new InputStreamReader(
                context.getResources().openRawResource(resourceId)));

        try {//from   ww w  .j  ava2s  . co  m
            for (String line = reader.readLine(); line != null; line = reader
                    .readLine()) {
                builder.append(line).append("\n");
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        return builder.toString();
    }

}

Related Tutorials