Back to project page GreenGear.
The source code is released under:
MIT License
If you think the Android project GreenGear listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.bradleycurran.greengear.util; /*from w ww .j a v a2 s .c o m*/ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import android.content.Context; /** * Various utility methods to help with assets. * * @author Bradley Curran */ public class AssetUtil { private static final String TAG = AssetUtil.class.getSimpleName(); private static final String FORMAT_UTF8 = "UTF-8"; /** * Gets a given file from the assets directory and returns it as a string. * * @param context * @param filename * A file in the assets directory of your application. A valid file would be in * /assets/data.txt, which you would refer to with "data.txt". * @return The contents of a file as a string, otherwise null if there was an IO error. */ public static String get(Context context, String filename) { StringBuilder sb = new StringBuilder(); try { InputStream is = context.getAssets().open(filename); InputStreamReader isr = new InputStreamReader(is, FORMAT_UTF8); BufferedReader reader = new BufferedReader(isr); String line = null; while ((line = reader.readLine()) != null) { sb.append(line); } reader.close(); } catch (IOException e) { Log.e(TAG, "error", e); return null; } return sb.toString(); } }