0

I am attempting to source a txt document to be used with my program to parse sentences for swear words. In order to load the file swear.txt located in my program's assets directory(It wasn't initially populated, I had to create the folder under my main project folder manually). I use the code below:

try {
    sWord = new Scanner(new FileReader("file:///android_asset/swear.txt"));
    swearWord.add(sWord.next());
    sWord.close();
} catch (FileNotFoundException e) {
    e.printStackTrace();
}
Scanner opp;

When running the application I am given a "FileNotFoundException." I am guessing that I am incorrectly sourcing the file and have attempted a variety of ways read the file, but I am stumped at this point. I am not sure if this is because I had to manually create the file. In some of the examples I looked up they listed a raw file that should be in the main project directory, but my project has no such /raw file. Thank you for your time.

Mykaelous
  • 3
  • 1

1 Answers1

0

You can get assets by the following code:

String assetsName = "swear.txt"; 
InputStream assetsIS = context.getAssets().open( assetsName );
sWord = new Scanner(assetsIS);
...
DenisMath
  • 547
  • 4
  • 8