I was trying to copy the text file data from sd card to an array. While trying in platformIO getting error for myFile.read() line. Below is the code snippet
FIle MyFile;
char buf[50];
myFile = SD.open("test.txt");
if (myFile) {
int l = myFile.size();
Serial.println(l);
while (myFile.available()) {
myFile.read(buf,50);
}
// close the file:
myFile.close();
} else {
// If the file didn't open, print an error:
Serial.println("error opening test.txt");
}
it was showing error for the line myFile.read(buf,50);
And if I try to print myFile it works properly. Below is the code snippet for that
File myFile;
myFile = SD.open("test.txt");
if (myFile) {
int l = myFile.size();
Serial.println(l);
Serial.println("test.txt:");
// read from the file until there's nothing else in it:
while (myFile.available()) {
Serial.write(myFile.read());
}
// close the file:
myFile.close();
} else {
// If the file didn't open, print an error:
Serial.println("error opening test.txt");
}
Please provide any way to resolve the issue