Very confused about my PrintWriter object

Okay, so, I’m making a calculator. I started using the PrintWriter and BufferedReader objects so I could save previously entered problems, even after I exit the sketch.

Problem is, it kinda has to save a lot of data to the file. There’s no feasible limit to how long a line could get, and each entry in the line has some attached metadata, which adds even more to the load.

I didn’t realize until now, though, that when your file gets really big, the text saving mechanism kinda messes up. I’ll just see a line in the text file that says “null null null null nu”. It kinda just stops.

I think the flush function might be useful in stopping this…I think? But I can’t tell how often I’m supposed to use the flush function. And, overall, I feel like there’s gotta be a better way to edit the text file than using createWriter to clear the entire file, using a buffered reader to put everything back in the file, and adding the 3 extra lines I needed before closing.