Skip to content

Instantly share code, notes, and snippets.

@JosiasSena
Created July 15, 2016 23:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JosiasSena/d6954b66678c93ab79d26e4beb894e09 to your computer and use it in GitHub Desktop.
Save JosiasSena/d6954b66678c93ab79d26e4beb894e09 to your computer and use it in GitHub Desktop.
Load string from a file in Asset folder
public static String getStringFromAssetFile(final Context context, final String filename) {
final int MAX_BUFF = 1024 * 100;
final InputStream is;
final InputStreamReader isr;
final BufferedReader br;
String resultData = "";
try {
final AssetManager am = context.getAssets();
is = am.open(filename);
isr = new InputStreamReader(is, "UTF-8");
br = new BufferedReader(isr, MAX_BUFF);
final StringBuilder sb = new StringBuilder();
while ((resultData = br.readLine()) != null) {
sb.append(resultData).append("\n");
}
resultData = sb.toString();
br.close();
isr.close();
is.close();
} catch (final Exception e) {
RLog.e(TAG, e.getMessage(), e);
}
return resultData;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment