I am running a 4*4 maze all possible solution finding programme.I have set up a method that takes a random combination Value of"R, G, B, Y" as aStrin and checks if the given String is a valid solution or not. for instance, the given String is "RGGGBYYBBGYBGRR".
new Thread(() -> { //List<String> temp1 = new ArrayList<>(); String[] letters = {"R","G","B","Y"}; int done = 0; Cell start = MazeBuilder.mazeFor(REPO_NAME); while (done != 1) { String str = ""; int r = ThreadLocalRandom.current().nextInt(10, 48); //done = check(temp1, letters, done, start, str, r); for (int j = 0; j < r; j++) { Random rnd = new Random(); int index = rnd.nextInt(letters.length); str += letters[index]; } if (Helper.isValidSolution(start, str)) { done = 1; try { FileWriter FW = new FileWriter("ansGrid.txt"); FW.write(str); FW.close(); } catch (IOException e) { e.printStackTrace(); } } } }).start();
so my question is... if the programme crashes or it runs out of memory, how can I store the values of the temp1 variable in a file?