Can't send a file through sd card to serial port.

Hey guys,
I am using an arduino Uno connected with sd card and an adafruit adapter and a pushbutton. When the push-button is pressed it takes the time using the millis function and stores it to a file in Sd card. My problem occurs when I am trying to code it to send the file to the serial port and nothing happens. I am trying to send the number 1 through the serial monitor and then the micro controller display back the file. Here's the code

    if (Serial.read() == 1) {
    
      if (!dataFile.open("datalog.txt", O_READ)) {
    sd.errorHalt("opening datalog.txt for read failed");
  }
   Serial.write(dataFile.read());
  // close the file:
    dataFile.close();
      }

The number 1 when sent through the serial monitor is actually the ascii character '1', which has the value of 49 .

Test for '1', not 1.

-br

Thanks for your reply. I tested it but it gives me a " ÿ " as an output.

That's usually caused by unconditionally reading the serial port when you don't know that there is data to receive. q.v. serial.available.

I used serial.available and change the "==1" to "=='1'" and it is finally working. Thank u guys!