Created
July 18, 2018 05:51
-
-
Save umuieme/bdece71a43305e438ec6c9a2756c3129 to your computer and use it in GitHub Desktop.
Utility method related to file manipulation
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 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