Arduino DUE dos not Write After Reading from SD

Context: i have two files on an SD card, file A and File B. in the Set up void, i am opening one file, reading the contents, closing and then repeating it for the second file.

I then later on in the void loop, try to write to the SD card File C and file D.

i open the file, write and close, and repeat.

so far i am only able to read A and B, or Write C and D, i am not able to do both in the same sketch.

CODE:

void setup() {
  SD.begin(53);

Data_logger = SD.open("A.txt");
    
    while (Data_logger.available())
    {

      A_sd_read = Data_logger.read();

      // do stuff with the stuff
    }
     
   Data_logger.close(); 


// read B
    
    Data_logger = SD.open("B.txt");
    
    while (Data_logger.available())
    {

      PWM_sd_read[i] = Data_logger.read();

   // do stuff with the stuff
    }
     
    Data_logger.close();
}

void loop() {

Data_logger_reg = SD.open("C.txt",FILE_WRITE);      
  Data_logger_reg.print(C_Stuff);
}

That is not a complete sketch and won't even compile. Who knows what the problem is. It is best to create a complete sketch that demonstrates the issue.

That aside, you don't appear to be checking to see if the open() call is successful before attempting a write. I also see no evidence of closing the file inside of loop(), yet to attempt to open the file every time through the loop.

Cross Post:

https://forum.arduino.cc/index.php?topic=589485.0