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.InputStream;
import android.content.res.Resources;

public class Main {

    public static String getStringFromAssets(String strFileName, Resources resources) {
        String result = null;
        try {
            InputStream in = resources.getAssets().open(strFileName);
            int ch = 0;
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            while ((ch = in.read()) != -1) {
                baos.write(ch);
            }
            byte[] buff = baos.toByteArray();
            baos.close();
            in.close();
            result = new String(buff);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }
}