Skip to content

Instantly share code, notes, and snippets.

@ssaurel
Created January 1, 2020 08:15
Show Gist options
  • Select an option

  • Save ssaurel/ad6b5089a937a13ecc5d3dfd4475d31e to your computer and use it in GitHub Desktop.

Select an option

Save ssaurel/ad6b5089a937a13ecc5d3dfd4475d31e to your computer and use it in GitHub Desktop.
loadWords method from Anagram Finder tutorial on SSaurel's Blog
// Method for loading words from assets
public static void loadWords(Context context) {
BufferedReader buf = null;
try {
buf = new BufferedReader(new InputStreamReader(context.getAssets().open(DICT)));
String line = null;
// we read file line by line to store words
while ((line = buf.readLine()) != null) {
WORDS.add(line.toUpperCase()); // we set words in upper case to make things easier when searching anagrams for entered letters
}
LOADED = true;
} catch (IOException ioe) {
// ...
} finally {
if (buf != null) {
try {
buf.close();
} catch (IOException e) {
// ...
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment