Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.io.FileInputStream;

import java.io.IOException;

import android.content.Context;

public class Main {
    private static Context sCurrentContext;

    /**
     * <pre>
     * Read binary data from file stored in app 's internal memory.
     * </pre>
     * @param absolutePath absolute path to source file
     * @return binary data
     */
    public static byte[] readInternalFile(String absolutePath) throws IOException {
        FileInputStream in = getCurrentContext().openFileInput(absolutePath);
        byte[] b = new byte[in.available()];
        in.read(b);
        in.close();

        return b;
    }

    /**
     * <pre>
     * Get current context of the app. This method resolves the inconvenience of Android which requires context for most of its API.
     * If no activity is resumed, this method returns application context. Otherwise, this method returns last resumed activity.
     * </pre>
     */
    public static Context getCurrentContext() {
        return sCurrentContext;
    }
}