0

I create a class called dictionary which extends InputMethodService. I want to read a text file which is in assets folder. But I cannot read the text file

So, I write two print statement to check the code, when I run the below code

        System.out.println("before ");
        AssetManager assetManager = getAssets();
        System.out.println("after ");
        InputStream is = assetManager.open( startingLetter+".txt");

output is "before" only

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • 1
    Possible duplicate of [How to Read/Write String from a File in Android](https://stackoverflow.com/questions/14376807/how-to-read-write-string-from-a-file-in-android) – Tamir Abutbul Apr 07 '19 at 11:06
  • After I did that there was an exception @TamirAbutbul (I/System.out: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.AssetManager android.content.Context.getAssets()' on a null object reference) – chathura kapugedara Apr 07 '19 at 12:47
  • I want to know where the file should be stored – chathura kapugedara Apr 07 '19 at 12:57

1 Answers1

0

Try this code

try {
    System.out.println("before ");
    AssetManager assetManager = getAssets();
    System.out.println("after ");
    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(assetManager.open
            (".txt")));
}catch(IOException e){
    exception.printStackTrace();
}
kaizen
  • 1,132
  • 1
  • 14
  • 20