Cannot resolve openFileInput method (Android Development)

I get an error "can not resolve the method" with the line of code:

FileInputStream fis = openFileInput(fileName);

I'm not in acitivty. I am in a separate class, so I assume this will not work. I tried to do such things, but they still give me a way to "not allow" Error:

FileInputStream fis = getApplicationContext.openFileInput(fileName);

Thanks for any help, I am new to Android development.

+4
source share
2 answers

I had a similar case when I could not use openFileInputor openFileOutput, but in a class that was not active. In my case, however, I already passed the context to the method, so I just did

context.openFileInput("stuff.dat");

If you can do something like this, it solves.

+7
source

, , , . Activity Context, Context :

  protected void onCreate(String filename,Context context) {
  try
 {
     FileInputStream fis = context.openFileInput(filename);  
     //...your code here...      
 }
 catch (Exception ex)
 {

 }
}
+1

All Articles