get file from assets folders - Android App

Android examples for App:Assets File

Description

get file from assets folders

Demo Code


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

public class Main {
    /**/*from w ww.  j  a v  a2  s . c  o m*/
     * get file from assets folders
     * @param context
     * @param filename
     * @return fileString
     * */
    public static String getFromAssets(Context con, String fileName) {
        String Result = "";
        try {
            InputStreamReader inputReader = new InputStreamReader(con
                    .getAssets().open(fileName));
            BufferedReader bufReader = new BufferedReader(inputReader);
            String line = "";
            while ((line = bufReader.readLine()) != null)
                Result += line;
            return Result;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result;
    }
}

Related Tutorials