I have code that is inside my Activity class to load and save a file. It works fine. The code saves the contents of cFavretClass. I’m trying to clean up the code, so I moved the file i/o into the cFavret Class.
I cannot get the code to compile. Now I get an error saying openFileOutput is undefined in type cFavrets.
I’m assuming that this method was declared in Googles Activity Class?
Does this mean all file I/O must be in the activity class?
boolean Save()
{
String FILENAME = "hello_file";
try {
FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE );
fos.write(buffer);
fos.close();
}
// just catch all exceptions and return false
catch (Throwable t) {
return false;
}
return true;
}
boolean Load()
{
String FILENAME = "hello_file";
try {
FileInputStream fos = openFileInput(FILENAME);
buffer[0]=0;
fos.read(buffer);
fos.close();
}
// just catch all exceptions and return false
catch (Throwable t) {
// maybe file does not exist, try creating it
return false;
}
return true;
}
No, but the method in question is called from a context – just pass a context into the constructor of this
cFavretClass(or to the method itself, if you prefer):