SdFat reading into a 512 byte array

I can't figure out how to read a load of bytes into a byte array. For instance the code below outputs "50" when I would like it to have filled the byte array with B10000000 (128). I had it working with single bytes using SD but it took 39 milliseconds to read 1024 bytes and I wanted to reduce that time.

#include <SPI.h>
#include <SdFat.h>

SdFat sd;
SdFile myFile;

const int chipSelect = 9;
byte data[512];

void setup()
{
  Serial.begin(115200);
  pinMode(chipSelect, OUTPUT);
  
  if (!sd.begin(chipSelect, SPI_HALF_SPEED)) {
    sd.initErrorHalt();
  }

  WriteData();  
  ReadData();

  Serial.println(data[400]);
}

void loop()
{
}

void ReadData()
{
  if (!myFile.open("test.txt")) {
    sd.errorHalt("opening test.txt for read failed");
  }  
  myFile.read(&data,512);
  myFile.close();
}

void WriteData()
{
  if(sd.exists("test.txt")) {
     sd.remove("test.txt");
   }

  if (!myFile.open("test.txt", O_RDWR | O_CREAT | O_AT_END)) {
    sd.errorHalt("ofailed");
  }
 
  for(int i=0;i<1024;i++) {
    myFile.print(B10000000);
  }
  myFile.close();
}

Any suggestions would be most welcome. Cheers!

Falesh:
I can't figure out how to read a load of bytes into a byte array. For instance the code below outputs "50" when I would like it to have filled the byte array with B10000000 (128). I had it working with single bytes using SD but it took 39 milliseconds to read 1024 bytes and I wanted to reduce that time.

Review the docs on the Stream class. The read/write functions of SD are implemented using Stream.

try this:

void ReadData()
{
  if (!myFile.open("test.txt")) {
    sd.errorHalt("opening test.txt for read failed");
  }  
  int16_t count=myFile.readBytes(&data,512);
 myFile.close();
 
 Serial.print(" count of bytes read =");
 Serial.println(count,DEC);
}

Chuck.

I was being daft. By using myFile.print I was writing the bytes as ascii characters, i.e. "1", "0", "0", etc. I changed to myFile.write and it works. :stuck_out_tongue: