I want to use internal storage (opennFileOutput
) in database helper. This is my code:
public class DBDAO {
protected SQLiteDatabase database;
private DatabaseHelper dbHelper;
private Context mContext;
public DBDAO(Context context) {
this.mContext = context;
dbHelper = new DatabaseHelper(mContext);
}
public void WriteFile(String writeString) {
// add-write text into file
try {
FileOutputStream fileout = openFileOutput("language.txt", MODE_PRIVATE);
OutputStreamWriter outputWriter = new OutputStreamWriter(fileout);
outputWriter.write(writeString);
outputWriter.close();
} catch (Exception e) {
e.printStackTrace();
}
}
// Read text from file
public String ReadFile() {
// reading text from file
String s = "";
try {
FileInputStream fileIn = openFileInput("language.txt");
InputStreamReader InputRead = new InputStreamReader(fileIn);
char[] inputBuffer = new char[100];
int charRead;
while ((charRead = InputRead.read(inputBuffer)) > 0) {
// char to string conversion
String readstring = String
.copyValueOf(inputBuffer, 0, charRead);
s += readstring;
}
InputRead.close();
} catch (Exception e) {
e.printStackTrace();
}
return s;
}
}
But, error in: OpenFileOutput : MODE_PRIVATE cannot be resolved to a variable
and: The method openFileInput(String) is undefined for the type DBDAO
So somebody can show me how to solve it?
Thanks so much and sorry because my english.
Aucun commentaire:
Enregistrer un commentaire