Created
January 1, 2020 08:15
-
-
Save ssaurel/ad6b5089a937a13ecc5d3dfd4475d31e to your computer and use it in GitHub Desktop.
loadWords method from Anagram Finder tutorial on SSaurel's Blog
This file contains hidden or 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
| // 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