Answers for "write file to internal storage android"

0

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();
}
Posted by: Guest on July-03-2021

Code answers related to "write file to internal storage android"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language