Load Asset JSON File - Android App

Android examples for App:Assets File

Description

Load Asset JSON File

Demo Code


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

public class Main {
    public static String AssetJSONFile(Context context, String filename) {
        String json = null;/* w w w. ja v  a2  s  .c  o  m*/
        try {

            InputStream is = context.getAssets().open(filename);
            int size = is.available();
            byte[] buffer = new byte[size];
            is.read(buffer);
            is.close();
            json = new String(buffer, "UTF-8");

        } catch (IOException ex) {
            ex.printStackTrace();
            return null;
        }
        return json;

    }
}

Related Tutorials