Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import android.content.res.Resources;

public class Main {
    public static String getStringFromResRaw(int iResId, Resources resources) {
        InputStream inputStream = resources.openRawResource(iResId);
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

        int iLen = -1;
        byte[] buffer = new byte[512];
        try {
            while (-1 != (iLen = inputStream.read(buffer)))
                outputStream.write(buffer, 0, iLen);
            inputStream.close();
            return new String(outputStream.toByteArray());
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }

    }
}