Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import java.io.ByteArrayOutputStream;

import java.io.IOException;
import java.io.InputStream;

import android.content.res.Resources;

public class Main {
    /**
     * Load an asset from a resource and return the content as byte array.
     */
    public static byte[] assetAsByteArray(Resources res, String path) throws IOException {
        InputStream is = res.getAssets().open(path);

        ByteArrayOutputStream buf = new ByteArrayOutputStream();
        byte[] temp = new byte[1024];
        int read;

        while ((read = is.read(temp)) > 0) {
            buf.write(temp, 0, read);
        }
        is.close();
        return buf.toByteArray();
    }
}