Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import android.content.Context;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

public class Main {
    public static String getResourceText(Context context, int resId) {
        InputStream is = null;
        BufferedInputStream bis;
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        try {
            is = context.getResources().openRawResource(resId);
            bis = new BufferedInputStream(is);
            int result = bis.read();
            while (result != -1) {
                byte b = (byte) result;
                baos.write(b);
                result = bis.read();
            }
        } catch (IOException e) {
        } finally {
            try {
                if (is != null)
                    is.close();
            } catch (IOException e) {
            }
        }
        return baos.toString();
    }
}