Electronhub.com - searching electronic component made easy

Android Reading File From Assets

To read file from the assets folder in android
we can use:



context.getAssets().open(filename)


Simple Example for reading the JSON file as string from the assets folder




 public static String ReadFileToString(Context context, String filename)
    {

        String json = null;
        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 (Exception ex) {
            ex.printStackTrace();
            return null;
        }
        return json;
    }



Comments

  1. How to Make Money from Betting on Sports Betting - Work
    (don't worry if 토토 사이트 you get it wrong, titanium earrings though) The process worrione involves placing bets on different events, but หารายได้เสริม it can also be done by using the wooricasinos.info

    ReplyDelete

Post a Comment