Skip to content

Instantly share code, notes, and snippets.

@umuieme
Created July 18, 2018 05:51
Show Gist options
  • Save umuieme/bdece71a43305e438ec6c9a2756c3129 to your computer and use it in GitHub Desktop.
Save umuieme/bdece71a43305e438ec6c9a2756c3129 to your computer and use it in GitHub Desktop.
Utility method related to file manipulation
public class FileUtils {
public static String getDataFromAsset(Context context, String fileName) {
String data = "";
BufferedReader in = null;
try {
InputStream inputStream = context.getAssets().open(fileName);
StringBuilder buf = new StringBuilder();
in = new BufferedReader(new InputStreamReader(inputStream));
String str;
while ((str = in.readLine()) != null) {
buf.append(str);
}
in.close();
return buf.toString();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return "";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment