Cannot write file to sketch space

Hi @enonod,

not having much time but guess this is enough for you as a starting point…

import android.os.Environment;
import android.content.Context;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.util.ArrayList;

void setup() {
  size(585, 585); // 785
  String infilename = "inSavedGames.txt"; // file you roll out with deployment
  String outfilename = "outSavedGames.txt"; // file which can be modified on device

  // Load strings from file
  String[] savedGames = loadStrings(infilename);
  if (savedGames == null) {
    println("Error: Input file not found");
    return;
  }
  // show content of input file
  println("----------------------------");
  println("content of source file :" + infilename);
  for (String s : savedGames) {
    println(s);
  }
  println("Number of lines in input file: " + savedGames.length);  // This prints 4 for strings in file & array

  println("----------------------------");
  // write content of input file to device
  String absolutePath = getActivity().getFileStreamPath(outfilename).getAbsolutePath();
  try (PrintWriter p = new PrintWriter(getActivity().openFileOutput(outfilename, Context.MODE_PRIVATE))) {
    for (String s : savedGames) {
      println(String.format("writing (%s) to file: %s", s, absolutePath));
      p.println(s);
    }
  }
  catch (Exception e) {
    println("Error writing: " + e);
  }

  println("----------------------------");
  // read content of file on device
  ArrayList<String> content = new ArrayList<>();
  try (FileInputStream fis = getActivity().openFileInput(outfilename);
  InputStreamReader inputStreamReader = new InputStreamReader(fis);
  BufferedReader reader = new BufferedReader(inputStreamReader)) {

    String line = reader.readLine();
    while (line != null) {
      content.add(line);
      println(String.format("reading (%s) from file: %s", line, absolutePath));
      line = reader.readLine();
    }
  }
  catch (Exception e) {
    println("Error reading: " + e);
  }

  println("----------------------------");
  // show content after reading on device
  println("Number of lines from output file: " + content.size());  // This prints 4 for strings in file & array
  println("content after reading:");
  for (String s : content) {
    println(s);
  }
}

void draw() {
}

console output:

----------------------------
content of source file :inSavedGames.txt
Line1
Line2
Line3
Line4
Number of lines in input file: 4
----------------------------
writing (Line1) to file: /data/user/0/processing.test.androidfile/files/outSavedGames.txt
writing (Line2) to file: /data/user/0/processing.test.androidfile/files/outSavedGames.txt
writing (Line3) to file: /data/user/0/processing.test.androidfile/files/outSavedGames.txt
writing (Line4) to file: /data/user/0/processing.test.androidfile/files/outSavedGames.txt
----------------------------
reading (Line1) from file: /data/user/0/processing.test.androidfile/files/outSavedGames.txt
reading (Line2) from file: /data/user/0/processing.test.androidfile/files/outSavedGames.txt
reading (Line3) from file: /data/user/0/processing.test.androidfile/files/outSavedGames.txt
reading (Line4) from file: /data/user/0/processing.test.androidfile/files/outSavedGames.txt
----------------------------
Number of lines from output file: 4
content after reading:
Line1
Line2
Line3
Line4

Hope that helps …

Cheers
— mnse