SPIFSS write byte or char array into a file

Hi!
I tried adapting the following topic on how to write a byte-array to a binary file:
link
But after writing, when I open the file, there is 0 bytes.
My code:

#include <SPIFFS.h>
  if(!SPIFFS.begin(true)){
    Serial.println("An Error has occurred while mounting SPIFFS");
  }
#define frame_total 50688
byte mem[frame_total];
  for ( unsigned int i=0; i<frame_total; i++) {
    mem[i] = 0x00;  // fill with '0's
  }
File file = SPIFFS.open("/test.bmp", "wb");  // binary write mode
file.write(mem, frame_total);
file.close();
//test size
File file2 = SPIFFS.open("/test.bmp", "rb");  // binary read mode
Serial.println(file2.size());   // Serial output result: 0
file2.close();

Please, how to write a byte or char array and retrieve it?
Thank you!

This value is too large for a signed integer. Perhaps use unsigned int or size_t instead.

Thank you jfjlaros I made a mstake writing this topic:
#define frame_total 50688

it depends on what controller OP has. Since OP uses of SPIFS, I guess that this is esp8266 or esp32 - and on these controllers the int type is 4 bytes

1 Like

Try writing a smaller array first, such as 32 bytes.

ESP32. I Will try 32 bits.
Thank you.

Ok. I'll try

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.