get File From Raw - Android App

Android examples for App:Raw

Description

get File From Raw

Demo Code


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

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static String geFileFromRaw(Context context, int resId) {
        if (context == null) {
            return null;
        }//from  w w w .j  a v  a  2s  . c  o 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