Created
July 15, 2016 23:22
-
-
Save JosiasSena/d6954b66678c93ab79d26e4beb894e09 to your computer and use it in GitHub Desktop.
Load string from a file in Asset folder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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