Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.content.Context;
import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

public class Main {
    /**
     * From http://stackoverflow.com/questions/9544737/read-file-from-assets
     */
    public static String readAsset(Context context, String fileName) throws IOException {
        BufferedReader reader = new BufferedReader(
                new InputStreamReader(context.getAssets().open(fileName), "UTF-8"));

        String line;
        StringBuilder stringBuilder = new StringBuilder();

        while ((line = reader.readLine()) != null)
            stringBuilder.append(line + "\n");

        reader.close();
        return stringBuilder.toString();
    }
}