Reads asset file from given name of the file - Android App

Android examples for App:Assets File

Description

Reads asset file from given name of the file

Demo Code


//package com.java2s;

import java.io.InputStream;

import android.content.Context;

public class Main {
    /**/*from   w ww.  j  a  v a  2 s  .com*/
     * Reads asset file from given name of the file
     * @param fileName
     * @return
     */
    public static String readAssetFile(Context context, String fileName) {
        InputStream file;

        try {
            file = context.getAssets().open(fileName);
            byte[] data = new byte[file.available()];
            file.read(data);
            file.close();
            return new String(data);
        } catch (Exception e) {
        }

        return "";
    }
}

Related Tutorials