write file to internal storage android
public static boolean saveToInternalStorage(String data, String filename, Context context) throws IOException {
FileOutputStream fos = context.openFileOutput(filename, Context.MODE_PRIVATE);
//default mode is PRIVATE, can be APPEND etc.
fos.write(data.getBytes());
fos.close();
return true;
}
public static String readFileFromInternalStorage(String filename, Context context) throws IOException {
FileInputStream fis = context.openFileInput(filename);
InputStreamReader isr = new InputStreamReader(fis);
BufferedReader bufferedReader = new BufferedReader(isr);
StringBuilder sb = new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null) {
sb.append(line);
}
bufferedReader.close();
return sb.toString();
}