Skip to content

Instantly share code, notes, and snippets.

@vamsitallapudi
Last active January 16, 2018 07:02
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 vamsitallapudi/0ede4a0e283c43788faf34cc6c8d3ff3 to your computer and use it in GitHub Desktop.
Save vamsitallapudi/0ede4a0e283c43788faf34cc6c8d3ff3 to your computer and use it in GitHub Desktop.
Read a file in Java Using Buffered Reader
BufferedReader reader = null;
try {
reader = new BufferedReader(
new InputStreamReader(getAssets().open("news_data_file.json"), "UTF-8"));
// do reading, usually loop until end of file reading
String mLine;
while ((mLine = reader.readLine()) != null) {
//process line
...
}
} catch (IOException e) {
//log the exception
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
//log the exception
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment