18
I'm trying to read in a text file of a bunch of words that I want to use for a word game I am writing. This list is stored in the assets directory and is a txt file. But, whenever I attempt to open it, it throws an exception.
List<String>wordList = new ArrayList<String>();
BufferedReader br = null;
try {
br = new BufferedReader(new InputStreamReader(getAssets().open("wordlist.txt"))); //throwing a FileNotFoundException?
String word;
while((word=br.readLine()) != null)
wordList.add(word); //break txt file into different words, add to wordList
}
catch(IOException e) {
e.printStackTrace();
}
finally {
try {
br.close(); //stop reading
}
catch(IOException ex) {
ex.printStackTrace();
}
}
String[]words = new String[wordList.size()];
wordList.toArray(words); //make array of wordList
for(int i=0;i<words.length; i++)
Log.i("Brian", words[i]); //print out words in array
}
Here's the error log, in case that's any help:
02-22 20:49:47.646: WARN/System.err(2351): java.io.FileNotFoundException: wordlist.txt
02-22 20:49:47.646: WARN/System.err(2351): at android.content.res.AssetManager.openAsset(Native Method)
02-22 20:49:47.746: WARN/System.err(2351): at android.content.res.AssetManager.open(AssetManager.java:299)
02-22 20:49:47.746: WARN/System.err(2351): at android.content.res.AssetManager.open(AssetManager.java:273)
02-22 20:49:47.756: WARN/System.err(2351): at com.bic.anagram.GameActivity.onCreate(GameActivity.java:40)
02-22 20:49:47.756: WARN/System.err(2351): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-22 20:49:47.756: WARN/System.err(2351): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2521)
02-22 20:49:47.756: WARN/Sy